Search in sources :

Example 91 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 92 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)

Example 93 with Semaphore

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

the class VideoEditorPreviewTest method testPreviewWithOverlay.

/**
     * To test Preview : Preview of current Overlay applied
     */
@LargeTest
public void testPreviewWithOverlay() throws Exception {
    final String videoItemFileName = INPUT_FILE_PATH + "MPEG4_SP_640x480_15fps_1200kbps_AACLC_48khz_64kbps_m_1_17.3gp";
    final String overlayFilename1 = INPUT_FILE_PATH + "IMG_640x480_Overlay1.png";
    final String overlayFilename2 = INPUT_FILE_PATH + "IMG_640x480_Overlay2.png";
    final int previewFrom = 5000;
    final int previewTo = 10000;
    final boolean previewLoop = false;
    final int previewCallbackFrameCount = 1;
    final int setAspectRatio = MediaProperties.ASPECT_RATIO_4_3;
    final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    final Semaphore blockTillPreviewCompletes = new Semaphore(1);
    previewStart = false;
    previewStop = false;
    boolean flagForException = false;
    final MediaVideoItem mediaVideoItem = mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", videoItemFileName, renderingMode);
    mVideoEditor.addMediaItem(mediaVideoItem);
    mediaVideoItem.setExtractBoundaries(0, 10000);
    final Bitmap mBitmap1 = mVideoEditorHelper.getBitmap(overlayFilename1, 640, 480);
    final OverlayFrame overlayOnMvi1 = mVideoEditorHelper.createOverlay(mediaVideoItem, "OverlayOnMvi1", mBitmap1, 0, 5000);
    mediaVideoItem.addOverlay(overlayOnMvi1);
    final Bitmap mBitmap2 = mVideoEditorHelper.getBitmap(overlayFilename2, 640, 480);
    final OverlayFrame overlayOnMvi2 = mVideoEditorHelper.createOverlay(mediaVideoItem, "OverlayOnMvi2", mBitmap2, 5000, 9000);
    mediaVideoItem.addOverlay(overlayOnMvi2);
    List<Overlay> overlayList = mediaVideoItem.getAllOverlays();
    assertEquals("Overlay Size", 2, overlayList.size());
    assertEquals("Overlay 1", overlayOnMvi1, overlayList.get(0));
    assertEquals("Overlay 2", overlayOnMvi2, overlayList.get(1));
    mVideoEditor.setAspectRatio(setAspectRatio);
    validatePreviewProgress(0, /* previewFrom */
    -1, previewLoop, mVideoEditor.getDuration());
}
Also used : Bitmap(android.graphics.Bitmap) MediaVideoItem(android.media.videoeditor.MediaVideoItem) OverlayFrame(android.media.videoeditor.OverlayFrame) Semaphore(java.util.concurrent.Semaphore) Overlay(android.media.videoeditor.Overlay) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 94 with Semaphore

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

the class VideoEditorPreviewTest method testPreviewWithTrim.

/**
     * To test Preview : Preview of current Trim applied (with default aspect
     * ratio)
     */
@LargeTest
public void testPreviewWithTrim() throws Exception {
    final String videoItemFileName = INPUT_FILE_PATH + "H264_BP_640x480_30fps_192kbps_1_5.mp4";
    final MediaVideoItem mediaVideoItem = mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", videoItemFileName, MediaItem.RENDERING_MODE_CROPPING);
    final Semaphore blockTillPreviewCompletes = new Semaphore(1);
    boolean flagForException = false;
    previewStart = false;
    previewStop = false;
    mediaVideoItem.setExtractBoundaries(mediaVideoItem.getDuration() / 2, mediaVideoItem.getDuration());
    mVideoEditor.addMediaItem(mediaVideoItem);
    validatePreviewProgress(1000, -1, false, mVideoEditor.getDuration());
}
Also used : MediaVideoItem(android.media.videoeditor.MediaVideoItem) Semaphore(java.util.concurrent.Semaphore) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 95 with Semaphore

use of java.util.concurrent.Semaphore in project storm-mesos by nathanmarz.

the class MesosSupervisor method prepare.

@Override
public void prepare(Map conf, String localDir) {
    try {
        _state = new LocalState(localDir);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    Semaphore initter = new Semaphore(0);
    _executor = new StormExecutor(initter);
    _driver = new MesosExecutorDriver(_executor);
    _driver.start();
    LOG.info("Waiting for executor to initialize...");
    try {
        initter.acquire();
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
    LOG.info("Executor initialized...");
    Thread suicide = new SuicideDetector(conf);
    suicide.setDaemon(true);
    suicide.start();
}
Also used : MesosExecutorDriver(org.apache.mesos.MesosExecutorDriver) LocalState(backtype.storm.utils.LocalState) IOException(java.io.IOException) 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