public class TextureMovieEncoder
extends java.lang.Object
implements java.lang.Runnable
The object wraps an encoder running on a dedicated thread. The various control messages may be sent from arbitrary threads (typically the app UI thread). The encoder thread manages both sides of the encoder (feeding and draining); the only external input is the GL texture.
The design is complicated slightly by the need to create an EGL activity that shares state with a view that gets restarted if (say) the device orientation changes. When the view in question is a GLSurfaceView, we don't have full control over the EGL activity creation on that side, so we have to bend a bit backwards here.
To use:
Modifier and Type | Class and Description |
---|---|
static class |
TextureMovieEncoder.EncoderConfig
Encoder configuration.
|
Constructor and Description |
---|
TextureMovieEncoder() |
Modifier and Type | Method and Description |
---|---|
void |
frameAvailable(android.graphics.SurfaceTexture st)
Tells the video recorder that a new frame is available.
|
int |
getFrameRate() |
boolean |
isRecording()
Returns true if recording has been started.
|
void |
releaseRecording() |
void |
run()
Encoder thread entry point.
|
void |
setEffect(Texture2dProgram.ProgramType programType) |
void |
setFrameRate(int framerate) |
void |
setTextureId(int id)
Tells the video recorder what texture name to use.
|
boolean |
startRecording(TextureMovieEncoder.EncoderConfig config,
long mRecordingStartTime)
Tells the video recorder to start recording.
|
void |
stopRecording()
Tells the video recorder to stop recording.
|
void |
updateSharedContext(android.opengl.EGLContext sharedContext)
Tells the video recorder to refresh its EGL surface.
|
public boolean startRecording(TextureMovieEncoder.EncoderConfig config, long mRecordingStartTime)
Creates a new thread, which will create an encoder using the provided configuration.
Returns after the recorder thread has started and is ready to accept Messages. The encoder may not yet be fully configured.
public void releaseRecording()
public void stopRecording()
Returns immediately; the encoder/muxer may not yet be finished creating the movie.
TODO: have the encoder thread invoke a callback on the UI thread just before it shuts down so we can provide reasonable status UI (and let the caller know that movie encoding has completed).
public boolean isRecording()
public void updateSharedContext(android.opengl.EGLContext sharedContext)
public void frameAvailable(android.graphics.SurfaceTexture st)
This function sends a message and returns immediately. This isn't sufficient -- we don't want the caller to latch a new frame until we're done with this one -- but we can get away with it so long as the input frame rate is reasonable and the encoder thread doesn't stall.
TODO: either block here until the texture has been rendered onto the encoder surface, or have a separate "block if still busy" method that the caller can execute immediately before it calls updateTexImage(). The latter is preferred because we don't want to stall the caller while this thread does work.
public void setFrameRate(int framerate)
public int getFrameRate()
public void setTextureId(int id)
TODO: do something less clumsy
public void setEffect(Texture2dProgram.ProgramType programType)
public void run()
run
in interface java.lang.Runnable
Thread.run()