Search in sources :

Example 26 with Surface

use of android.view.Surface in project XobotOS by xamarin.

the class VideoEditorImpl method renderPreviewFrame.

/*
     * {@inheritDoc}
     */
public long renderPreviewFrame(SurfaceHolder surfaceHolder, long timeMs, OverlayData overlayData) {
    if (surfaceHolder == null) {
        throw new IllegalArgumentException("Surface Holder is null");
    }
    final Surface surface = surfaceHolder.getSurface();
    if (surface == null) {
        throw new IllegalArgumentException("Surface could not be retrieved from Surface holder");
    }
    if (surface.isValid() == false) {
        throw new IllegalStateException("Surface is not valid");
    }
    if (timeMs < 0) {
        throw new IllegalArgumentException("requested time not correct");
    } else if (timeMs > mDurationMs) {
        throw new IllegalArgumentException("requested time more than duration");
    }
    long result = 0;
    boolean semAcquireDone = false;
    try {
        semAcquireDone = lock(ENGINE_ACCESS_MAX_TIMEOUT_MS);
        if (semAcquireDone == false) {
            throw new IllegalStateException("Timeout waiting for semaphore");
        }
        if (mMANativeHelper == null) {
            throw new IllegalStateException("The video editor is not initialized");
        }
        if (mMediaItems.size() > 0) {
            final Rect frame = surfaceHolder.getSurfaceFrame();
            result = mMANativeHelper.renderPreviewFrame(surface, timeMs, frame.width(), frame.height(), overlayData);
        } else {
            result = 0;
        }
    } catch (InterruptedException ex) {
        Log.w(TAG, "The thread was interrupted", new Throwable());
        throw new IllegalStateException("The thread was interrupted");
    } finally {
        if (semAcquireDone) {
            unlock();
        }
    }
    return result;
}
Also used : Rect(android.graphics.Rect) Surface(android.view.Surface)

Example 27 with Surface

use of android.view.Surface in project VitamioBundle by yixia.

the class MediaPlayerDemo_setSurface method playVideo.

@SuppressLint("NewApi")
private void playVideo(SurfaceTexture surfaceTexture) {
    doCleanUp();
    try {
        path = "";
        if (path == "") {
            // Tell the user to provide a media file URL.
            Toast.makeText(MediaPlayerDemo_setSurface.this, "Please edit MediaPlayerDemo_setSurface Activity, " + "and set the path variable to your media file path." + " Your media file must be stored on sdcard.", Toast.LENGTH_LONG).show();
            return;
        }
        // Create a new media player and set the listeners
        mMediaPlayer = new MediaPlayer(this, true);
        mMediaPlayer.setDataSource(path);
        if (surf == null) {
            surf = new Surface(surfaceTexture);
        }
        mMediaPlayer.setSurface(surf);
        mMediaPlayer.prepareAsync();
        mMediaPlayer.setOnBufferingUpdateListener(this);
        mMediaPlayer.setOnCompletionListener(this);
        mMediaPlayer.setOnPreparedListener(this);
        setVolumeControlStream(AudioManager.STREAM_MUSIC);
    } catch (Exception e) {
        Log.e(TAG, "error: " + e.getMessage(), e);
    }
}
Also used : MediaPlayer(io.vov.vitamio.MediaPlayer) Surface(android.view.Surface) SuppressLint(android.annotation.SuppressLint)

Example 28 with Surface

use of android.view.Surface in project platform_frameworks_base by android.

the class CameraDeviceImpl method createReprocessableCaptureSession.

@Override
public void createReprocessableCaptureSession(InputConfiguration inputConfig, List<Surface> outputs, CameraCaptureSession.StateCallback callback, Handler handler) throws CameraAccessException {
    if (DEBUG) {
        Log.d(TAG, "createReprocessableCaptureSession");
    }
    if (inputConfig == null) {
        throw new IllegalArgumentException("inputConfig cannot be null when creating a " + "reprocessable capture session");
    }
    List<OutputConfiguration> outConfigurations = new ArrayList<>(outputs.size());
    for (Surface surface : outputs) {
        outConfigurations.add(new OutputConfiguration(surface));
    }
    createCaptureSessionInternal(inputConfig, outConfigurations, callback, handler, /*isConstrainedHighSpeed*/
    false);
}
Also used : OutputConfiguration(android.hardware.camera2.params.OutputConfiguration) ArrayList(java.util.ArrayList) Surface(android.view.Surface)

Example 29 with Surface

use of android.view.Surface in project platform_frameworks_base by android.

the class CameraDeviceImpl method createCaptureSessionInternal.

private void createCaptureSessionInternal(InputConfiguration inputConfig, List<OutputConfiguration> outputConfigurations, CameraCaptureSession.StateCallback callback, Handler handler, boolean isConstrainedHighSpeed) throws CameraAccessException {
    synchronized (mInterfaceLock) {
        if (DEBUG) {
            Log.d(TAG, "createCaptureSessionInternal");
        }
        checkIfCameraClosedOrInError();
        if (isConstrainedHighSpeed && inputConfig != null) {
            throw new IllegalArgumentException("Constrained high speed session doesn't support" + " input configuration yet.");
        }
        // After this call completes, the session is not allowed to call into CameraDeviceImpl
        if (mCurrentSession != null) {
            mCurrentSession.replaceSessionClose();
        }
        // TODO: dont block for this
        boolean configureSuccess = true;
        CameraAccessException pendingException = null;
        Surface input = null;
        try {
            // configure streams and then block until IDLE
            configureSuccess = configureStreamsChecked(inputConfig, outputConfigurations, isConstrainedHighSpeed);
            if (configureSuccess == true && inputConfig != null) {
                input = mRemoteDevice.getInputSurface();
            }
        } catch (CameraAccessException e) {
            configureSuccess = false;
            pendingException = e;
            input = null;
            if (DEBUG) {
                Log.v(TAG, "createCaptureSession - failed with exception ", e);
            }
        }
        List<Surface> outSurfaces = new ArrayList<>(outputConfigurations.size());
        for (OutputConfiguration config : outputConfigurations) {
            outSurfaces.add(config.getSurface());
        }
        // Fire onConfigured if configureOutputs succeeded, fire onConfigureFailed otherwise.
        CameraCaptureSessionCore newSession = null;
        if (isConstrainedHighSpeed) {
            newSession = new CameraConstrainedHighSpeedCaptureSessionImpl(mNextSessionId++, outSurfaces, callback, handler, this, mDeviceHandler, configureSuccess, mCharacteristics);
        } else {
            newSession = new CameraCaptureSessionImpl(mNextSessionId++, input, outSurfaces, callback, handler, this, mDeviceHandler, configureSuccess);
        }
        // TODO: wait until current session closes, then create the new session
        mCurrentSession = newSession;
        if (pendingException != null) {
            throw pendingException;
        }
        mSessionStateCallback = mCurrentSession.getDeviceStateCallback();
    }
}
Also used : CameraAccessException(android.hardware.camera2.CameraAccessException) OutputConfiguration(android.hardware.camera2.params.OutputConfiguration) ArrayList(java.util.ArrayList) Surface(android.view.Surface)

Example 30 with Surface

use of android.view.Surface in project platform_frameworks_base by android.

the class CameraDeviceImpl method submitCaptureRequest.

private int submitCaptureRequest(List<CaptureRequest> requestList, CaptureCallback callback, Handler handler, boolean repeating) throws CameraAccessException {
    // Need a valid handler, or current thread needs to have a looper, if
    // callback is valid
    handler = checkHandler(handler, callback);
    // Make sure that there all requests have at least 1 surface; all surfaces are non-null
    for (CaptureRequest request : requestList) {
        if (request.getTargets().isEmpty()) {
            throw new IllegalArgumentException("Each request must have at least one Surface target");
        }
        for (Surface surface : request.getTargets()) {
            if (surface == null) {
                throw new IllegalArgumentException("Null Surface targets are not allowed");
            }
        }
    }
    synchronized (mInterfaceLock) {
        checkIfCameraClosedOrInError();
        if (repeating) {
            stopRepeating();
        }
        SubmitInfo requestInfo;
        CaptureRequest[] requestArray = requestList.toArray(new CaptureRequest[requestList.size()]);
        requestInfo = mRemoteDevice.submitRequestList(requestArray, repeating);
        if (DEBUG) {
            Log.v(TAG, "last frame number " + requestInfo.getLastFrameNumber());
        }
        if (callback != null) {
            mCaptureCallbackMap.put(requestInfo.getRequestId(), new CaptureCallbackHolder(callback, requestList, handler, repeating, mNextSessionId - 1));
        } else {
            if (DEBUG) {
                Log.d(TAG, "Listen for request " + requestInfo.getRequestId() + " is null");
            }
        }
        if (repeating) {
            if (mRepeatingRequestId != REQUEST_ID_NONE) {
                checkEarlyTriggerSequenceComplete(mRepeatingRequestId, requestInfo.getLastFrameNumber());
            }
            mRepeatingRequestId = requestInfo.getRequestId();
        } else {
            mRequestLastFrameNumbersList.add(new RequestLastFrameNumbersHolder(requestList, requestInfo));
        }
        if (mIdle) {
            mDeviceHandler.post(mCallOnActive);
        }
        mIdle = false;
        return requestInfo.getRequestId();
    }
}
Also used : SubmitInfo(android.hardware.camera2.utils.SubmitInfo) CaptureRequest(android.hardware.camera2.CaptureRequest) 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