use of android.view.Surface in project android_frameworks_base by ParanoidAndroid.
the class VideoEditorImpl method startPreview.
/*
* {@inheritDoc}
*/
public void startPreview(SurfaceHolder surfaceHolder, long fromMs, long toMs, boolean loop, int callbackAfterFrameCount, PreviewProgressListener listener) {
if (surfaceHolder == null) {
throw new IllegalArgumentException();
}
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 (listener == null) {
throw new IllegalArgumentException();
}
if (fromMs >= mDurationMs) {
throw new IllegalArgumentException("Requested time not correct");
}
if (fromMs < 0) {
throw new IllegalArgumentException("Requested time not correct");
}
boolean semAcquireDone = false;
if (!mPreviewInProgress) {
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) {
mPreviewInProgress = true;
mMANativeHelper.previewStoryBoard(mMediaItems, mTransitions, mAudioTracks, null);
mMANativeHelper.doPreview(surface, fromMs, toMs, loop, callbackAfterFrameCount, listener);
}
/**
* Release The lock on complete by calling stopPreview
*/
} catch (InterruptedException ex) {
Log.w(TAG, "The thread was interrupted", new Throwable());
throw new IllegalStateException("The thread was interrupted");
}
} else {
throw new IllegalStateException("Preview already in progress");
}
}
use of android.view.Surface in project android_frameworks_base by ParanoidAndroid.
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;
}
use of android.view.Surface in project android_frameworks_base by ParanoidAndroid.
the class GLEnvironment method registerSurfaceTexture.
public int registerSurfaceTexture(SurfaceTexture surfaceTexture, int width, int height) {
Surface surface = new Surface(surfaceTexture);
int result = nativeAddSurfaceWidthHeight(surface, width, height);
surface.release();
if (result < 0) {
throw new RuntimeException("Error registering surfaceTexture " + surfaceTexture + "!");
}
return result;
}
use of android.view.Surface in project android_frameworks_base by ParanoidAndroid.
the class MediaSource method setupMediaPlayer.
/** Creates a media player, sets it up, and calls prepare */
private synchronized boolean setupMediaPlayer(boolean useUrl) {
mPrepared = false;
mGotSize = false;
mPlaying = false;
mPaused = false;
mCompleted = false;
mNewFrameAvailable = false;
if (mLogVerbose)
Log.v(TAG, "Setting up playback.");
if (mMediaPlayer != null) {
// Clean up existing media players
if (mLogVerbose)
Log.v(TAG, "Resetting existing MediaPlayer.");
mMediaPlayer.reset();
} else {
// Create new media player
if (mLogVerbose)
Log.v(TAG, "Creating new MediaPlayer.");
mMediaPlayer = new MediaPlayer();
}
if (mMediaPlayer == null) {
throw new RuntimeException("Unable to create a MediaPlayer!");
}
// Set up data sources, etc
try {
if (useUrl) {
if (mLogVerbose)
Log.v(TAG, "Setting MediaPlayer source to URI " + mSourceUrl);
if (mContext == null) {
mMediaPlayer.setDataSource(mSourceUrl);
} else {
mMediaPlayer.setDataSource(mContext, Uri.parse(mSourceUrl.toString()));
}
} else {
if (mLogVerbose)
Log.v(TAG, "Setting MediaPlayer source to asset " + mSourceAsset);
mMediaPlayer.setDataSource(mSourceAsset.getFileDescriptor(), mSourceAsset.getStartOffset(), mSourceAsset.getLength());
}
} catch (IOException e) {
mMediaPlayer.release();
mMediaPlayer = null;
if (useUrl) {
throw new RuntimeException(String.format("Unable to set MediaPlayer to URL %s!", mSourceUrl), e);
} else {
throw new RuntimeException(String.format("Unable to set MediaPlayer to asset %s!", mSourceAsset), e);
}
} catch (IllegalArgumentException e) {
mMediaPlayer.release();
mMediaPlayer = null;
if (useUrl) {
throw new RuntimeException(String.format("Unable to set MediaPlayer to URL %s!", mSourceUrl), e);
} else {
throw new RuntimeException(String.format("Unable to set MediaPlayer to asset %s!", mSourceAsset), e);
}
}
mMediaPlayer.setLooping(mLooping);
mMediaPlayer.setVolume(mVolume, mVolume);
// Bind it to our media frame
Surface surface = new Surface(mSurfaceTexture);
mMediaPlayer.setSurface(surface);
surface.release();
// Connect Media Player to callbacks
mMediaPlayer.setOnVideoSizeChangedListener(onVideoSizeChangedListener);
mMediaPlayer.setOnPreparedListener(onPreparedListener);
mMediaPlayer.setOnCompletionListener(onCompletionListener);
// Connect SurfaceTexture to callback
mSurfaceTexture.setOnFrameAvailableListener(onMediaFrameAvailableListener);
if (mLogVerbose)
Log.v(TAG, "Preparing MediaPlayer.");
mMediaPlayer.prepareAsync();
return true;
}
use of android.view.Surface in project android_frameworks_base by ParanoidAndroid.
the class EGLImpl method eglCreateWindowSurface.
public EGLSurface eglCreateWindowSurface(EGLDisplay display, EGLConfig config, Object native_window, int[] attrib_list) {
Surface sur = null;
if (native_window instanceof SurfaceView) {
SurfaceView surfaceView = (SurfaceView) native_window;
sur = surfaceView.getHolder().getSurface();
} else if (native_window instanceof SurfaceHolder) {
SurfaceHolder holder = (SurfaceHolder) native_window;
sur = holder.getSurface();
} else if (native_window instanceof Surface) {
sur = (Surface) native_window;
}
int eglSurfaceId;
if (sur != null) {
eglSurfaceId = _eglCreateWindowSurface(display, config, sur, attrib_list);
} else if (native_window instanceof SurfaceTexture) {
eglSurfaceId = _eglCreateWindowSurfaceTexture(display, config, native_window, attrib_list);
} else {
throw new java.lang.UnsupportedOperationException("eglCreateWindowSurface() can only be called with an instance of " + "Surface, SurfaceView, SurfaceHolder or SurfaceTexture at the moment.");
}
if (eglSurfaceId == 0) {
return EGL10.EGL_NO_SURFACE;
}
return new EGLSurfaceImpl(eglSurfaceId);
}
Aggregations