use of com.android.grafika.gles.WindowSurface in project grafika by google.
the class TextureMovieEncoder method prepareEncoder.
private void prepareEncoder(EGLContext sharedContext, int width, int height, int bitRate, File outputFile) {
try {
mVideoEncoder = new VideoEncoderCore(width, height, bitRate, outputFile);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
mEglCore = new EglCore(sharedContext, EglCore.FLAG_RECORDABLE);
mInputWindowSurface = new WindowSurface(mEglCore, mVideoEncoder.getInputSurface(), true);
mInputWindowSurface.makeCurrent();
mFullScreen = new FullFrameRect(new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT));
}
use of com.android.grafika.gles.WindowSurface in project grafika by google.
the class GeneratedMovie method prepareEncoder.
/**
* Prepares the video encoder, muxer, and an EGL input surface.
*/
protected void prepareEncoder(String mimeType, int width, int height, int bitRate, int framesPerSecond, File outputFile) throws IOException {
mBufferInfo = new MediaCodec.BufferInfo();
MediaFormat format = MediaFormat.createVideoFormat(mimeType, width, height);
// Set some properties. Failing to specify some of these can cause the MediaCodec
// configure() call to throw an unhelpful exception.
format.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
format.setInteger(MediaFormat.KEY_BIT_RATE, bitRate);
format.setInteger(MediaFormat.KEY_FRAME_RATE, framesPerSecond);
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, IFRAME_INTERVAL);
if (VERBOSE)
Log.d(TAG, "format: " + format);
// Create a MediaCodec encoder, and configure it with our format. Get a Surface
// we can use for input and wrap it with a class that handles the EGL work.
mEncoder = MediaCodec.createEncoderByType(mimeType);
mEncoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
Log.v(TAG, "encoder is " + mEncoder.getCodecInfo().getName());
Surface surface;
try {
surface = mEncoder.createInputSurface();
} catch (IllegalStateException ise) {
// TODO: failure message should come out of strings.xml for i18n
if (isSoftwareCodec(mEncoder)) {
throw new RuntimeException("Can't use input surface with software codec: " + mEncoder.getCodecInfo().getName(), ise);
} else {
throw new RuntimeException("Failed to create input surface", ise);
}
}
mEglCore = new EglCore(null, EglCore.FLAG_RECORDABLE);
mInputSurface = new WindowSurface(mEglCore, surface, true);
mInputSurface.makeCurrent();
mEncoder.start();
// the raw H.264 elementary stream we get from MediaCodec into a .mp4 file.
if (VERBOSE)
Log.d(TAG, "output will go to " + outputFile);
mMuxer = new MediaMuxer(outputFile.toString(), MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
mTrackIndex = -1;
mMuxerStarted = false;
}
use of com.android.grafika.gles.WindowSurface in project grafika by google.
the class MultiSurfaceActivity method drawRectSurface.
/**
* Clears the surface, then draws some alpha-blended rectangles with GL.
* <p>
* Creates a temporary EGL context just for the duration of the call.
*/
private void drawRectSurface(Surface surface, int left, int top, int width, int height) {
EglCore eglCore = new EglCore();
WindowSurface win = new WindowSurface(eglCore, surface, false);
win.makeCurrent();
GLES20.glClearColor(0, 0, 0, 0);
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
for (int i = 0; i < 4; i++) {
int x, y, w, h;
if (width < height) {
// vertical
w = width / 4;
h = height;
x = left + w * i;
y = top;
} else {
// horizontal
w = width;
h = height / 4;
x = left;
y = top + h * i;
}
GLES20.glScissor(x, y, w, h);
switch(i) {
case // 50% blue at 25% alpha, pre-multiplied
0:
GLES20.glClearColor(0.0f, 0.0f, 0.125f, 0.25f);
break;
case // 100% blue at 25% alpha, pre-multiplied
1:
GLES20.glClearColor(0.0f, 0.0f, 0.25f, 0.25f);
break;
case // 200% blue at 25% alpha, pre-multiplied (should get clipped)
2:
GLES20.glClearColor(0.0f, 0.0f, 0.5f, 0.25f);
break;
case // 100% white at 25% alpha, pre-multiplied
3:
GLES20.glClearColor(0.25f, 0.25f, 0.25f, 0.25f);
break;
}
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
}
GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
win.swapBuffers();
win.release();
eglCore.release();
}
use of com.android.grafika.gles.WindowSurface in project grafika by google.
the class PlayMovieSurfaceActivity method clearSurface.
/**
* Clears the playback surface to black.
*/
private void clearSurface(Surface surface) {
// We need to do this with OpenGL ES (*not* Canvas -- the "software render" bits
// are sticky). We can't stay connected to the Surface after we're done because
// that'd prevent the video encoder from attaching.
//
// If the Surface is resized to be larger, the new portions will be black, so
// clearing to something other than black may look weird unless we do the clear
// post-resize.
EglCore eglCore = new EglCore();
WindowSurface win = new WindowSurface(eglCore, surface, false);
win.makeCurrent();
GLES20.glClearColor(0, 0, 0, 0);
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
win.swapBuffers();
win.release();
eglCore.release();
}
use of com.android.grafika.gles.WindowSurface in project grafika by google.
the class ContinuousCaptureActivity method surfaceCreated.
// SurfaceHolder.Callback
@Override
public void surfaceCreated(SurfaceHolder holder) {
Log.d(TAG, "surfaceCreated holder=" + holder);
// Set up everything that requires an EGL context.
//
// We had to wait until we had a surface because you can't make an EGL context current
// without one, and creating a temporary 1x1 pbuffer is a waste of time.
//
// The display surface that we use for the SurfaceView, and the encoder surface we
// use for video, use the same EGL context.
mEglCore = new EglCore(null, EglCore.FLAG_RECORDABLE);
mDisplaySurface = new WindowSurface(mEglCore, holder.getSurface(), false);
mDisplaySurface.makeCurrent();
mFullFrameBlit = new FullFrameRect(new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT));
mTextureId = mFullFrameBlit.createTextureObject();
mCameraTexture = new SurfaceTexture(mTextureId);
mCameraTexture.setOnFrameAvailableListener(this);
Log.d(TAG, "starting camera preview");
try {
mCamera.setPreviewTexture(mCameraTexture);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
mCamera.startPreview();
// (can we guarantee that camera preview size is compatible with AVC video encoder?)
try {
mCircEncoder = new CircularEncoder(VIDEO_WIDTH, VIDEO_HEIGHT, 6000000, mCameraPreviewThousandFps / 1000, 7, mHandler);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
mEncoderSurface = new WindowSurface(mEglCore, mCircEncoder.getInputSurface(), true);
updateControls();
}
Aggregations