Search in sources :

Example 81 with Semaphore

use of java.util.concurrent.Semaphore in project StickerCamera by Skykai521.

the class GPUImageView method capture.

/**
     * Capture the current image with the size as it is displayed and retrieve it as Bitmap.
     * @return current output as Bitmap
     * @throws InterruptedException
     */
public Bitmap capture() throws InterruptedException {
    final Semaphore waiter = new Semaphore(0);
    final int width = mGLSurfaceView.getMeasuredWidth();
    final int height = mGLSurfaceView.getMeasuredHeight();
    // Take picture on OpenGL thread
    final int[] pixelMirroredArray = new int[width * height];
    mGPUImage.runOnGLThread(new Runnable() {

        @Override
        public void run() {
            final IntBuffer pixelBuffer = IntBuffer.allocate(width * height);
            GLES20.glReadPixels(0, 0, width, height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, pixelBuffer);
            int[] pixelArray = pixelBuffer.array();
            // Convert upside down mirror-reversed image to right-side up normal image.
            for (int i = 0; i < height; i++) {
                for (int j = 0; j < width; j++) {
                    pixelMirroredArray[(height - i - 1) * width + j] = pixelArray[i * width + j];
                }
            }
            waiter.release();
        }
    });
    requestRender();
    waiter.acquire();
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    bitmap.copyPixelsFromBuffer(IntBuffer.wrap(pixelMirroredArray));
    return bitmap;
}
Also used : Bitmap(android.graphics.Bitmap) IntBuffer(java.nio.IntBuffer) Semaphore(java.util.concurrent.Semaphore)

Example 82 with Semaphore

use of java.util.concurrent.Semaphore in project android_frameworks_base by ParanoidAndroid.

the class CameraFunctionalTest method setUp.

protected void setUp() throws Exception {
    final Semaphore sem = new Semaphore(0);
    mLooperThread = new Thread() {

        @Override
        public void run() {
            Log.v(TAG, "starting looper");
            Looper.prepare();
            mHandler = new Handler();
            sem.release();
            Looper.loop();
            Log.v(TAG, "quit looper");
        }
    };
    mLooperThread.start();
    if (!sem.tryAcquire(WAIT_TIMEOUT, TimeUnit.MILLISECONDS)) {
        fail("Failed to start the looper.");
    }
    getActivity();
    super.setUp();
    mCameraTestHelper = new CameraTestHelper();
}
Also used : CameraTestHelper(com.android.mediaframeworktest.CameraTestHelper) Handler(android.os.Handler) Semaphore(java.util.concurrent.Semaphore)

Example 83 with Semaphore

use of java.util.concurrent.Semaphore in project android_frameworks_base by ParanoidAndroid.

the class CameraFunctionalTest method runOnLooper.

private void runOnLooper(final Runnable command) throws InterruptedException {
    final Semaphore sem = new Semaphore(0);
    mHandler.post(new Runnable() {

        @Override
        public void run() {
            try {
                command.run();
            } finally {
                sem.release();
            }
        }
    });
    if (!sem.tryAcquire(WAIT_TIMEOUT, TimeUnit.MILLISECONDS)) {
        fail("Failed to run the command on the looper.");
    }
}
Also used : Semaphore(java.util.concurrent.Semaphore)

Example 84 with Semaphore

use of java.util.concurrent.Semaphore in project android_frameworks_base by ParanoidAndroid.

the class CameraPairwiseTest method runOnLooper.

private void runOnLooper(final Runnable command) throws InterruptedException {
    final Semaphore sem = new Semaphore(0);
    mHandler.post(new Runnable() {

        @Override
        public void run() {
            try {
                command.run();
            } finally {
                sem.release();
            }
        }
    });
    if (!sem.tryAcquire(WAIT_TIMEOUT, TimeUnit.MILLISECONDS)) {
        fail("Failed to run the command on the looper.");
    }
}
Also used : Semaphore(java.util.concurrent.Semaphore)

Example 85 with Semaphore

use of java.util.concurrent.Semaphore in project android_frameworks_base by ParanoidAndroid.

the class CameraPairwiseTest method setUp.

protected void setUp() throws Exception {
    final Semaphore sem = new Semaphore(0);
    mLooperThread = new Thread() {

        @Override
        public void run() {
            Log.v(TAG, "starting looper");
            Looper.prepare();
            mHandler = new Handler();
            sem.release();
            Looper.loop();
            Log.v(TAG, "quit looper");
        }
    };
    mLooperThread.start();
    if (!sem.tryAcquire(WAIT_TIMEOUT, TimeUnit.MILLISECONDS)) {
        fail("Failed to start the looper.");
    }
    getActivity();
    super.setUp();
    mCameraTestHelper = new CameraTestHelper();
}
Also used : CameraTestHelper(com.android.mediaframeworktest.CameraTestHelper) Handler(android.os.Handler) Semaphore(java.util.concurrent.Semaphore)

Aggregations

Semaphore (java.util.concurrent.Semaphore)511 Test (org.junit.Test)198 IOException (java.io.IOException)55 Context (android.content.Context)39 InvocationOnMock (org.mockito.invocation.InvocationOnMock)38 ArrayList (java.util.ArrayList)37 HashMap (java.util.HashMap)36 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)31 AtomicReference (java.util.concurrent.atomic.AtomicReference)31 ExecutionException (java.util.concurrent.ExecutionException)30 File (java.io.File)29 Intent (android.content.Intent)27 List (java.util.List)27 Map (java.util.Map)26 CountDownLatch (java.util.concurrent.CountDownLatch)25 Handler (android.os.Handler)24 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)24 HazelcastInstance (com.hazelcast.core.HazelcastInstance)21 BroadcastReceiver (android.content.BroadcastReceiver)20 IntentFilter (android.content.IntentFilter)20