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();
}
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());
}
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());
}
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());
}
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();
}
Aggregations