Search in sources :

Example 26 with Semaphore

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

the class MediaRecorderStressTest 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.");
    }
    //Insert a 2 second before launching the test activity. This is
    //the workaround for the race condition of requesting the updated surface.
    Thread.sleep(2000);
    getActivity();
    super.setUp();
    File stressOutFile = new File(String.format("%s/%s", Environment.getExternalStorageDirectory(), MEDIA_STRESS_OUTPUT));
    mOutput = new BufferedWriter(new FileWriter(stressOutFile, true));
    mOutput.write(this.getName() + "\n");
}
Also used : FileWriter(java.io.FileWriter) Handler(android.os.Handler) Semaphore(java.util.concurrent.Semaphore) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 27 with Semaphore

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

the class CameraStressTest 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();
    File stressOutFile = new File(String.format("%s/%s", Environment.getExternalStorageDirectory(), CAMERA_STRESS_OUTPUT));
    mOutput = new BufferedWriter(new FileWriter(stressOutFile, true));
    mOutput.write(this.getName() + "\n");
}
Also used : CameraTestHelper(com.android.mediaframeworktest.CameraTestHelper) FileWriter(java.io.FileWriter) Handler(android.os.Handler) Semaphore(java.util.concurrent.Semaphore) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 28 with Semaphore

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

the class CameraStressTest 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 29 with Semaphore

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

the class VideoEditorPreviewTest method validatePreviewProgress.

protected void validatePreviewProgress(int startMs, int endMs, boolean loop, long duration) throws Exception {
    final int[] progressUpdate = new int[100];
    final Semaphore blockTillPreviewCompletes = new Semaphore(1);
    previewStart = false;
    previewStop = false;
    previewError = false;
    mVideoEditor.generatePreview(new MediaProcessingProgressListener() {

        int i = 0;

        public void onProgress(Object item, int action, int progress) {
            progressUpdate[i++] = progress;
        }
    });
    mVideoEditorHelper.checkProgressCBValues(progressUpdate);
    final SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
    long waitingTime = minWaitingTime;
    if (endMs == -1) {
        waitingTime += duration;
    } else {
        waitingTime += (endMs - startMs);
    }
    blockTillPreviewCompletes.acquire();
    try {
        mVideoEditor.startPreview(surfaceHolder, startMs, endMs, loop, 1, new PreviewProgressListener() {

            public void onProgress(VideoEditor videoEditor, long timeMs, OverlayData overlayData) {
                if (overlayData != null) {
                    if (overlayData.needsRendering()) {
                        overlayData.renderOverlay(MediaFrameworkTest.mDestBitmap);
                        mEventHandler.sendMessage(mEventHandler.obtainMessage(1, 2, 3));
                    }
                }
            }

            public void onStart(VideoEditor videoEditor) {
                setPreviewStart();
            }

            public void onStop(VideoEditor videoEditor) {
                setPreviewStop();
                blockTillPreviewCompletes.release();
            }

            public void onError(VideoEditor videoEditor, int error) {
                setPreviewError();
                blockTillPreviewCompletes.release();
            }
        });
    } catch (Exception e) {
        blockTillPreviewCompletes.release();
    }
    blockTillPreviewCompletes.tryAcquire(waitingTime, TimeUnit.MILLISECONDS);
    mVideoEditor.stopPreview();
    assertTrue("Preview Failed to start", previewStart);
    assertTrue("Preview Failed to stop", previewStop);
    assertFalse("Preview Error occurred", previewError);
    blockTillPreviewCompletes.release();
}
Also used : SurfaceHolder(android.view.SurfaceHolder) VideoEditor(android.media.videoeditor.VideoEditor) PreviewProgressListener(android.media.videoeditor.VideoEditor.PreviewProgressListener) MediaProcessingProgressListener(android.media.videoeditor.VideoEditor.MediaProcessingProgressListener) OverlayData(android.media.videoeditor.VideoEditor.OverlayData) Semaphore(java.util.concurrent.Semaphore) IOException(java.io.IOException)

Example 30 with Semaphore

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

the class VideoEditorPreviewTest method testPreviewOfEffects.

/**
     * To test Preview : Preview of current Effects applied
     */
@LargeTest
public void testPreviewOfEffects() throws Exception {
    final String videoItemFileName1 = INPUT_FILE_PATH + "H264_BP_640x480_30fps_256kbps_1_17.mp4";
    final Semaphore blockTillPreviewCompletes = new Semaphore(1);
    previewStart = false;
    previewStop = false;
    final MediaVideoItem mediaVideoItem1 = mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem1", videoItemFileName1, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mVideoEditor.addMediaItem(mediaVideoItem1);
    final EffectColor effectNegative = mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effectNegative", 0, 2000, EffectColor.TYPE_NEGATIVE, 0);
    mediaVideoItem1.addEffect(effectNegative);
    final EffectColor effectGreen = mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effectGreen", 2000, 3000, EffectColor.TYPE_COLOR, EffectColor.GREEN);
    mediaVideoItem1.addEffect(effectGreen);
    final EffectColor effectFifties = mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effectFifties", 5000, 4000, EffectColor.TYPE_FIFTIES, 0);
    mediaVideoItem1.addEffect(effectFifties);
    List<Effect> effectList = mediaVideoItem1.getAllEffects();
    assertEquals("Effect List Size", 3, effectList.size());
    assertEquals("Effect negative", effectNegative, effectList.get(0));
    assertEquals("Effect Green", effectGreen, effectList.get(1));
    assertEquals("Effect Fifties", effectFifties, effectList.get(2));
    mVideoEditor.setAspectRatio(MediaProperties.ASPECT_RATIO_4_3);
    assertEquals("Aspect Ratio", MediaProperties.ASPECT_RATIO_4_3, mVideoEditor.getAspectRatio());
    final long storyboardDuration = mVideoEditor.getDuration();
    validatePreviewProgress(0, (int) (storyboardDuration / 2), false, (storyboardDuration / 2));
    assertEquals("Removing Effect : Negative", effectNegative, mediaVideoItem1.removeEffect(effectNegative.getId()));
    effectList = mediaVideoItem1.getAllEffects();
    assertEquals("Effect List Size", 2, effectList.size());
    assertEquals("Effect Green", effectGreen, effectList.get(0));
    assertEquals("Effect Fifties", effectFifties, effectList.get(1));
    validatePreviewProgress(0, -1, false, mVideoEditor.getDuration());
}
Also used : EffectColor(android.media.videoeditor.EffectColor) MediaVideoItem(android.media.videoeditor.MediaVideoItem) Effect(android.media.videoeditor.Effect) Semaphore(java.util.concurrent.Semaphore) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

Semaphore (java.util.concurrent.Semaphore)447 Test (org.junit.Test)167 IOException (java.io.IOException)52 Context (android.content.Context)35 ArrayList (java.util.ArrayList)31 HashMap (java.util.HashMap)31 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)29 File (java.io.File)27 CountDownLatch (java.util.concurrent.CountDownLatch)25 ExecutionException (java.util.concurrent.ExecutionException)25 Intent (android.content.Intent)24 Handler (android.os.Handler)24 List (java.util.List)24 Map (java.util.Map)24 InvocationOnMock (org.mockito.invocation.InvocationOnMock)23 HazelcastInstance (com.hazelcast.core.HazelcastInstance)21 BroadcastReceiver (android.content.BroadcastReceiver)20 IntentFilter (android.content.IntentFilter)20 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)20 TimeoutException (java.util.concurrent.TimeoutException)19