Search in sources :

Example 86 with Semaphore

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

the class VideoEditorPreviewTest method testPreviewWithOverlayEffectKenBurn.

/**
     * To test Preview : Preview of current work having Overlay and Effect
     * applied
     */
@LargeTest
public void testPreviewWithOverlayEffectKenBurn() throws Exception {
    final String videoItemFileName = INPUT_FILE_PATH + "H264_BP_640x480_30fps_192kbps_1_5.mp4";
    final String imageItemFileName = INPUT_FILE_PATH + "IMG_640x480.jpg";
    final String videoItemFileName1 = INPUT_FILE_PATH + "MPEG4_SP_640x480_15fps_512kbps_AACLC_48khz_132kbps_s_0_26.mp4";
    final String overlayFilename = INPUT_FILE_PATH + "IMG_640x480_Overlay1.png";
    final Semaphore blockTillPreviewCompletes = new Semaphore(1);
    previewStart = false;
    previewStop = false;
    final MediaVideoItem mediaVideoItem1 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", videoItemFileName, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mVideoEditor.addMediaItem(mediaVideoItem1);
    final MediaImageItem mediaImageItem2 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", imageItemFileName, 10000, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mVideoEditor.addMediaItem(mediaImageItem2);
    final MediaVideoItem mediaVideoItem3 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", videoItemFileName1, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mVideoEditor.addMediaItem(mediaVideoItem3);
    final EffectColor effectColor = mVideoEditorHelper.createEffectItem(mediaVideoItem1, "Effect1", 1000, 3000, EffectColor.TYPE_COLOR, EffectColor.GREEN);
    mediaVideoItem1.addEffect(effectColor);
    final Rect startRect = new Rect((mediaImageItem2.getHeight() / 3), (mediaImageItem2.getWidth() / 3), (mediaImageItem2.getHeight() / 2), (mediaImageItem2.getWidth() / 2));
    final Rect endRect = new Rect(0, 0, mediaImageItem2.getWidth(), mediaImageItem2.getHeight());
    final EffectKenBurns kbeffectOnMI2 = new EffectKenBurns(mediaImageItem2, "KBOnM2", startRect, endRect, 0, 10000);
    assertNotNull("EffectKenBurns", kbeffectOnMI2);
    mediaImageItem2.addEffect(kbeffectOnMI2);
    final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayFilename, 640, 480);
    final OverlayFrame overlayFrame = mVideoEditorHelper.createOverlay(mediaVideoItem3, "OverlayID", mBitmap, (mediaImageItem2.getDuration() / 4), (mediaVideoItem3.getDuration() / 3));
    mediaVideoItem3.addOverlay(overlayFrame);
    validatePreviewProgress(5000, -1, false, mVideoEditor.getDuration());
}
Also used : Rect(android.graphics.Rect) Bitmap(android.graphics.Bitmap) EffectColor(android.media.videoeditor.EffectColor) EffectKenBurns(android.media.videoeditor.EffectKenBurns) MediaVideoItem(android.media.videoeditor.MediaVideoItem) MediaImageItem(android.media.videoeditor.MediaImageItem) OverlayFrame(android.media.videoeditor.OverlayFrame) Semaphore(java.util.concurrent.Semaphore) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 87 with Semaphore

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

the class VideoEditorPreviewTest method testPreviewWithTransition.

/**
     *To test Preview : Preview of current Transitions applied (with multiple
     * generatePreview)
     */
@LargeTest
public void testPreviewWithTransition() throws Exception {
    final String videoItemFileName1 = INPUT_FILE_PATH + "H263_profile0_176x144_10fps_96kbps_0_25.3gp";
    final String imageItemFileName1 = INPUT_FILE_PATH + "IMG_1600x1200.jpg";
    final String videoItemFileName2 = INPUT_FILE_PATH + "MPEG4_SP_800x480_515kbps_15fps_AMR_NB_8KHz_12.2kbps_m_0_26.mp4";
    final String maskFilename = INPUT_FILE_PATH + "TransitionSpiral_QVGA.jpg";
    previewStart = false;
    previewStop = false;
    previewError = false;
    final Semaphore blockTillPreviewCompletes = new Semaphore(1);
    final MediaVideoItem mediaVideoItem1 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", videoItemFileName1, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mediaVideoItem1.setExtractBoundaries(0, 10000);
    mVideoEditor.addMediaItem(mediaVideoItem1);
    final MediaImageItem mediaImageItem1 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", imageItemFileName1, 10000, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mVideoEditor.addMediaItem(mediaImageItem1);
    final MediaVideoItem mediaVideoItem2 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", videoItemFileName2, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mediaVideoItem2.setExtractBoundaries(0, 10000);
    mVideoEditor.addMediaItem(mediaVideoItem2);
    final TransitionCrossfade transition1And2CrossFade = mVideoEditorHelper.createTCrossFade("transition_1_2_CF", mediaVideoItem1, mediaImageItem1, 2000, Transition.BEHAVIOR_MIDDLE_FAST);
    mVideoEditor.addTransition(transition1And2CrossFade);
    final TransitionAlpha transition2And3Alpha = mVideoEditorHelper.createTAlpha("transition_2_3", mediaImageItem1, mediaVideoItem2, 4000, Transition.BEHAVIOR_SPEED_UP, maskFilename, 50, true);
    mVideoEditor.addTransition(transition2And3Alpha);
    final TransitionFadeBlack transition1FadeBlack = mVideoEditorHelper.createTFadeBlack("transition_1FB", null, mediaVideoItem1, 2000, Transition.BEHAVIOR_MIDDLE_FAST);
    mVideoEditor.addTransition(transition1FadeBlack);
    List<Transition> transitionList = mVideoEditor.getAllTransitions();
    assertEquals("Transition List Size", 3, transitionList.size());
    assertEquals("Transition 1", transition1And2CrossFade, transitionList.get(0));
    assertEquals("Transition 2", transition2And3Alpha, transitionList.get(1));
    assertEquals("Transition 3", transition1FadeBlack, transitionList.get(2));
    mVideoEditor.setAspectRatio(MediaProperties.ASPECT_RATIO_3_2);
    final int[] progressValues = new int[300];
    mVideoEditor.generatePreview(new MediaProcessingProgressListener() {

        int i = 0;

        public void onProgress(Object item, int action, int progress) {
            if (item instanceof TransitionCrossfade) {
                progressValues[i] = progress;
                assertEquals("Object", item, transition1And2CrossFade);
                assertEquals("Action", action, MediaProcessingProgressListener.ACTION_ENCODE);
            } else if (item instanceof TransitionAlpha) {
                progressValues[i] = progress;
                assertEquals("Object", item, transition2And3Alpha);
                assertEquals("Action", action, MediaProcessingProgressListener.ACTION_ENCODE);
            } else if (item instanceof TransitionFadeBlack) {
                progressValues[i] = progress;
                assertEquals("Object", item, transition1FadeBlack);
                assertEquals("Action", action, MediaProcessingProgressListener.ACTION_ENCODE);
            }
            i++;
        }
    });
    mVideoEditorHelper.checkProgressCBValues(progressValues);
    final SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
    /* As transition takes more time buffer of 10 sec is added */
    long waitingTime = minWaitingTime + 10000 + 10000;
    blockTillPreviewCompletes.acquire();
    try {
        mVideoEditor.startPreview(surfaceHolder, 0, 10000, false, 1, new PreviewProgressListener() {

            public void onProgress(VideoEditor videoEditor, long timeMs, OverlayData overlayData) {
            }

            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();
    blockTillPreviewCompletes.release();
    assertTrue("Preview Failed to start", previewStart);
    assertTrue("Preview Failed to stop", previewStop);
    assertFalse("Preview Error occurred", previewError);
    assertEquals("Removing Transition " + transition1And2CrossFade.getId(), transition1And2CrossFade, mVideoEditor.removeTransition(transition1And2CrossFade.getId()));
    transitionList = mVideoEditor.getAllTransitions();
    assertEquals("Transition List Size", 2, transitionList.size());
    assertEquals("Transition 1", transition2And3Alpha, transitionList.get(0));
    assertEquals("Transition 2", transition1FadeBlack, transitionList.get(1));
    validatePreviewProgress(0, -1, false, mVideoEditor.getDuration());
    final TransitionSliding transition1And2Sliding = mVideoEditorHelper.createTSliding("transition_1_2Sliding", mediaVideoItem1, mediaImageItem1, 4000, Transition.BEHAVIOR_MIDDLE_FAST, TransitionSliding.DIRECTION_LEFT_OUT_RIGHT_IN);
    mVideoEditor.addTransition(transition1And2Sliding);
    transitionList = mVideoEditor.getAllTransitions();
    assertEquals("Transition List Size", 3, transitionList.size());
    assertEquals("Transition 1", transition2And3Alpha, transitionList.get(0));
    assertEquals("Transition 2", transition1FadeBlack, transitionList.get(1));
    assertEquals("Transition 3", transition1And2Sliding, transitionList.get(2));
    validatePreviewProgress(5000, -1, false, (mVideoEditor.getDuration()));
}
Also used : VideoEditor(android.media.videoeditor.VideoEditor) TransitionFadeBlack(android.media.videoeditor.TransitionFadeBlack) MediaVideoItem(android.media.videoeditor.MediaVideoItem) MediaProcessingProgressListener(android.media.videoeditor.VideoEditor.MediaProcessingProgressListener) MediaImageItem(android.media.videoeditor.MediaImageItem) Semaphore(java.util.concurrent.Semaphore) TransitionCrossfade(android.media.videoeditor.TransitionCrossfade) IOException(java.io.IOException) TransitionAlpha(android.media.videoeditor.TransitionAlpha) SurfaceHolder(android.view.SurfaceHolder) PreviewProgressListener(android.media.videoeditor.VideoEditor.PreviewProgressListener) TransitionSliding(android.media.videoeditor.TransitionSliding) Transition(android.media.videoeditor.Transition) OverlayData(android.media.videoeditor.VideoEditor.OverlayData) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 88 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 89 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 90 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)

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