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