Loading media/java/android/media/videoeditor/MediaArtistNativeHelper.java +28 −1 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import java.nio.IntBuffer; import java.util.Iterator; import java.util.List; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; import android.graphics.Bitmap; import android.graphics.BitmapFactory; Loading Loading @@ -3058,6 +3059,8 @@ class MediaArtistNativeHelper { Log.e(TAG, "Runtime exception in nativeStartPreview"); throw ex; } } else { throw new IllegalStateException("generatePreview is in progress"); } } Loading Loading @@ -3085,7 +3088,10 @@ class MediaArtistNativeHelper { long renderPreviewFrame(Surface surface, long time, int surfaceWidth, int surfaceHeight, VideoEditor.OverlayData overlayData) { if (mInvalidatePreviewArray) { throw new RuntimeException("Call generate preview first"); if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Call generate preview first"); } throw new IllegalStateException("Call generate preview first"); } long timeMs = 0; Loading Loading @@ -3912,6 +3918,27 @@ class MediaArtistNativeHelper { } } /** * Tries to grab the semaphore with a specified time out which arbitrates access to the editor * * @param timeoutMs time out in ms. * * @return true if the semaphore is acquired, false otherwise * @throws InterruptedException */ boolean lock(long timeoutMs) throws InterruptedException { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "lock: grabbing semaphore with timeout " + timeoutMs, new Throwable()); } boolean acquireSem = mLock.tryAcquire(timeoutMs, TimeUnit.MILLISECONDS); if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "lock: grabbed semaphore status " + acquireSem); } return acquireSem; } /** * Release the semaphore which arbitrates access to the editor */ Loading media/java/android/media/videoeditor/VideoEditorImpl.java +15 −17 Original line number Diff line number Diff line Loading @@ -112,6 +112,7 @@ public class VideoEditorImpl implements VideoEditor { private static final String ATTR_OVERLAY_RESIZED_RGB_FRAME_WIDTH = "resized_RGBframe_width"; private static final String ATTR_OVERLAY_RESIZED_RGB_FRAME_HEIGHT = "resized_RGBframe_height"; private static final int ENGINE_ACCESS_MAX_TIMEOUT_MS = 500; /* * Instance variables */ Loading Loading @@ -852,8 +853,10 @@ public class VideoEditorImpl implements VideoEditor { boolean semAcquireDone = false; try { mMANativeHelper.lock(); semAcquireDone = true; semAcquireDone = mMANativeHelper.lock(ENGINE_ACCESS_MAX_TIMEOUT_MS); if (semAcquireDone == false) { throw new IllegalStateException("Timeout waiting for semaphore"); } if (mMediaItems.size() > 0) { final Rect frame = surfaceHolder.getSurfaceFrame(); Loading @@ -863,7 +866,8 @@ public class VideoEditorImpl implements VideoEditor { result = 0; } } catch (InterruptedException ex) { Log.e(TAG, "Sem acquire NOT successful in renderPreviewFrame"); Log.w(TAG, "The thread was interrupted", new Throwable()); throw new IllegalStateException("The thread was interrupted"); } finally { if (semAcquireDone) { mMANativeHelper.unlock(); Loading Loading @@ -1582,8 +1586,10 @@ public class VideoEditorImpl implements VideoEditor { boolean semAcquireDone = false; try{ mMANativeHelper.lock(); semAcquireDone = true; semAcquireDone = mMANativeHelper.lock(ENGINE_ACCESS_MAX_TIMEOUT_MS); if (semAcquireDone == false) { throw new IllegalStateException("Timeout waiting for semaphore"); } if (mMediaItems.size() > 0) { mMANativeHelper.previewStoryBoard(mMediaItems, mTransitions, Loading @@ -1596,16 +1602,8 @@ public class VideoEditorImpl implements VideoEditor { * release on complete by calling stopPreview */ } catch (InterruptedException ex) { Log.e(TAG, "Sem acquire NOT successful in startPreview"); } catch (IllegalArgumentException ex) { Log.e(TAG, "Illegal Argument exception in do preview"); throw ex; } catch (IllegalStateException ex) { Log.e(TAG, "Illegal State exception in do preview"); throw ex; } catch (RuntimeException ex) { Log.e(TAG, "Runtime exception in do preview"); throw ex; Log.w(TAG, "The thread was interrupted", new Throwable()); throw new IllegalStateException("The thread was interrupted"); } finally { if (semAcquireDone) { mMANativeHelper.unlock(); Loading Loading
media/java/android/media/videoeditor/MediaArtistNativeHelper.java +28 −1 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import java.nio.IntBuffer; import java.util.Iterator; import java.util.List; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; import android.graphics.Bitmap; import android.graphics.BitmapFactory; Loading Loading @@ -3058,6 +3059,8 @@ class MediaArtistNativeHelper { Log.e(TAG, "Runtime exception in nativeStartPreview"); throw ex; } } else { throw new IllegalStateException("generatePreview is in progress"); } } Loading Loading @@ -3085,7 +3088,10 @@ class MediaArtistNativeHelper { long renderPreviewFrame(Surface surface, long time, int surfaceWidth, int surfaceHeight, VideoEditor.OverlayData overlayData) { if (mInvalidatePreviewArray) { throw new RuntimeException("Call generate preview first"); if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Call generate preview first"); } throw new IllegalStateException("Call generate preview first"); } long timeMs = 0; Loading Loading @@ -3912,6 +3918,27 @@ class MediaArtistNativeHelper { } } /** * Tries to grab the semaphore with a specified time out which arbitrates access to the editor * * @param timeoutMs time out in ms. * * @return true if the semaphore is acquired, false otherwise * @throws InterruptedException */ boolean lock(long timeoutMs) throws InterruptedException { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "lock: grabbing semaphore with timeout " + timeoutMs, new Throwable()); } boolean acquireSem = mLock.tryAcquire(timeoutMs, TimeUnit.MILLISECONDS); if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "lock: grabbed semaphore status " + acquireSem); } return acquireSem; } /** * Release the semaphore which arbitrates access to the editor */ Loading
media/java/android/media/videoeditor/VideoEditorImpl.java +15 −17 Original line number Diff line number Diff line Loading @@ -112,6 +112,7 @@ public class VideoEditorImpl implements VideoEditor { private static final String ATTR_OVERLAY_RESIZED_RGB_FRAME_WIDTH = "resized_RGBframe_width"; private static final String ATTR_OVERLAY_RESIZED_RGB_FRAME_HEIGHT = "resized_RGBframe_height"; private static final int ENGINE_ACCESS_MAX_TIMEOUT_MS = 500; /* * Instance variables */ Loading Loading @@ -852,8 +853,10 @@ public class VideoEditorImpl implements VideoEditor { boolean semAcquireDone = false; try { mMANativeHelper.lock(); semAcquireDone = true; semAcquireDone = mMANativeHelper.lock(ENGINE_ACCESS_MAX_TIMEOUT_MS); if (semAcquireDone == false) { throw new IllegalStateException("Timeout waiting for semaphore"); } if (mMediaItems.size() > 0) { final Rect frame = surfaceHolder.getSurfaceFrame(); Loading @@ -863,7 +866,8 @@ public class VideoEditorImpl implements VideoEditor { result = 0; } } catch (InterruptedException ex) { Log.e(TAG, "Sem acquire NOT successful in renderPreviewFrame"); Log.w(TAG, "The thread was interrupted", new Throwable()); throw new IllegalStateException("The thread was interrupted"); } finally { if (semAcquireDone) { mMANativeHelper.unlock(); Loading Loading @@ -1582,8 +1586,10 @@ public class VideoEditorImpl implements VideoEditor { boolean semAcquireDone = false; try{ mMANativeHelper.lock(); semAcquireDone = true; semAcquireDone = mMANativeHelper.lock(ENGINE_ACCESS_MAX_TIMEOUT_MS); if (semAcquireDone == false) { throw new IllegalStateException("Timeout waiting for semaphore"); } if (mMediaItems.size() > 0) { mMANativeHelper.previewStoryBoard(mMediaItems, mTransitions, Loading @@ -1596,16 +1602,8 @@ public class VideoEditorImpl implements VideoEditor { * release on complete by calling stopPreview */ } catch (InterruptedException ex) { Log.e(TAG, "Sem acquire NOT successful in startPreview"); } catch (IllegalArgumentException ex) { Log.e(TAG, "Illegal Argument exception in do preview"); throw ex; } catch (IllegalStateException ex) { Log.e(TAG, "Illegal State exception in do preview"); throw ex; } catch (RuntimeException ex) { Log.e(TAG, "Runtime exception in do preview"); throw ex; Log.w(TAG, "The thread was interrupted", new Throwable()); throw new IllegalStateException("The thread was interrupted"); } finally { if (semAcquireDone) { mMANativeHelper.unlock(); Loading