Search in sources :

Example 21 with Surface

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;
}
Also used : MediaFormat(android.media.MediaFormat) MediaCodec(android.media.MediaCodec) EglCore(com.android.grafika.gles.EglCore) MediaMuxer(android.media.MediaMuxer) WindowSurface(com.android.grafika.gles.WindowSurface) WindowSurface(com.android.grafika.gles.WindowSurface) Surface(android.view.Surface)

Example 22 with Surface

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);
}
Also used : Surface(android.view.Surface)

Example 23 with 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();
    }
}
Also used : SurfaceHolder(android.view.SurfaceHolder) IOException(java.io.IOException) File(java.io.File) Surface(android.view.Surface) WindowSurface(com.android.grafika.gles.WindowSurface)

Example 24 with Surface

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);
    }
}
Also used : SurfaceTexture(android.graphics.SurfaceTexture) Surface(android.view.Surface)

Example 25 with Surface

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;
}
Also used : EGLSurface(android.opengl.EGLSurface) SurfaceTexture(android.graphics.SurfaceTexture) EGLSurface(android.opengl.EGLSurface) Surface(android.view.Surface)

Aggregations

Surface (android.view.Surface)300 ArrayList (java.util.ArrayList)100 SurfaceTexture (android.graphics.SurfaceTexture)49 BlockingSessionCallback (com.android.ex.camera2.blocking.BlockingSessionCallback)44 Size (android.util.Size)35 CaptureRequest (android.hardware.camera2.CaptureRequest)34 OutputConfiguration (android.hardware.camera2.params.OutputConfiguration)30 IOException (java.io.IOException)27 EGLSurface (android.opengl.EGLSurface)19 Paint (android.graphics.Paint)16 StreamConfigurationMap (android.hardware.camera2.params.StreamConfigurationMap)15 SurfaceHolder (android.view.SurfaceHolder)15 Rect (android.graphics.Rect)13 SurfaceView (android.view.SurfaceView)13 Canvas (android.graphics.Canvas)12 CameraAccessException (android.hardware.camera2.CameraAccessException)12 WifiDisplay (android.hardware.display.WifiDisplay)12 MediaRecorder (android.media.MediaRecorder)11 SurfaceControl (android.view.SurfaceControl)11 Image (android.media.Image)10