use of android.view.Surface 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 android.view.Surface in project grafika by google.
the class ColorBarActivity method surfaceChanged.
/**
* SurfaceHolder.Callback method
* <p>
* Draws when the surface changes. Since nothing else is touching the surface, and
* we're not animating, we just draw here and ignore it.
*/
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
Log.v(TAG, "surfaceChanged fmt=" + format + " size=" + width + "x" + height + " holder=" + holder);
Surface surface = holder.getSurface();
drawColorBars(surface);
}
use of android.view.Surface in project grafika by google.
the class PlayMovieSurfaceActivity method clickPlayStop.
/**
* onClick handler for "play"/"stop" button.
*/
public void clickPlayStop(@SuppressWarnings("unused") View unused) {
if (mShowStopLabel) {
Log.d(TAG, "stopping movie");
stopPlayback();
// Don't update the controls here -- let the task thread do it after the movie has
// actually stopped.
//mShowStopLabel = false;
//updateControls();
} else {
if (mPlayTask != null) {
Log.w(TAG, "movie already playing");
return;
}
Log.d(TAG, "starting movie");
SpeedControlCallback callback = new SpeedControlCallback();
SurfaceHolder holder = mSurfaceView.getHolder();
Surface surface = holder.getSurface();
// Don't leave the last frame of the previous video hanging on the screen.
// Looks weird if the aspect ratio changes.
clearSurface(surface);
MoviePlayer player = null;
try {
player = new MoviePlayer(new File(getFilesDir(), mMovieFiles[mSelectedMovie]), surface, callback);
} catch (IOException ioe) {
Log.e(TAG, "Unable to play movie", ioe);
surface.release();
return;
}
AspectFrameLayout layout = (AspectFrameLayout) findViewById(R.id.playMovie_afl);
int width = player.getVideoWidth();
int height = player.getVideoHeight();
layout.setAspectRatio((double) width / height);
//holder.setFixedSize(width, height);
mPlayTask = new MoviePlayer.PlayTask(player, this);
mShowStopLabel = true;
updateControls();
mPlayTask.execute();
}
}
use of android.view.Surface in project ExoPlayer by google.
the class SimpleExoPlayer method setVideoTextureView.
/**
* Sets the {@link TextureView} onto which video will be rendered. The player will track the
* lifecycle of the surface automatically.
*
* @param textureView The texture view.
*/
public void setVideoTextureView(TextureView textureView) {
removeSurfaceCallbacks();
this.textureView = textureView;
if (textureView == null) {
setVideoSurfaceInternal(null, true);
} else {
if (textureView.getSurfaceTextureListener() != null) {
Log.w(TAG, "Replacing existing SurfaceTextureListener.");
}
SurfaceTexture surfaceTexture = textureView.getSurfaceTexture();
setVideoSurfaceInternal(surfaceTexture == null ? null : new Surface(surfaceTexture), true);
textureView.setSurfaceTextureListener(componentListener);
}
}
use of android.view.Surface in project MagicCamera by wuhaoyu1990.
the class EglCore method createWindowSurface.
/**
* Creates an EGL surface associated with a Surface.
* <p>
* If this is destined for MediaCodec, the EGLConfig should have the "recordable" attribute.
*/
public EGLSurface createWindowSurface(Object surface) {
if (!(surface instanceof Surface) && !(surface instanceof SurfaceTexture)) {
throw new RuntimeException("invalid surface: " + surface);
}
// Create a window surface, and attach it to the Surface we received.
int[] surfaceAttribs = { EGL14.EGL_NONE };
EGLSurface eglSurface = EGL14.eglCreateWindowSurface(mEGLDisplay, mEGLConfig, surface, surfaceAttribs, 0);
checkEglError("eglCreateWindowSurface");
if (eglSurface == null) {
throw new RuntimeException("surface was null");
}
return eglSurface;
}
Aggregations