use of com.android.ddmlib.RawImage in project VideoOptimzer by attdevsupport.
the class VideoCaptureImpl method run.
/**
* Process to capture the image of emulator and pass the raw image to create
* a video.
*
* NOTE: If USB got disconnected, the Video capture thread will continue running.
* When the "isUSBConnected" was set to false ,we won't get any screen shot.
* The failure count in the catch blocks will be temporarily stopped until
* "isUSBConnected" become true.
*/
public void run() {
RawImage priorImage = null;
boolean captureFail = false;
int failCounter = 0;
if (device != null) {
RawImage rawImage = null;
BufferedImage image = null;
iExceptionCount = 0;
allDone = false;
Date lastFrameTime = this.videoStartTime = new Date();
hasExited = false;
isUSBConnected = true;
while (!allDone) {
try {
// Screen shot is captured from the emulator.
synchronized (device) {
if (isUSBConnected) {
try {
rawImage = device.getScreenshot();
priorImage = rawImage;
failCounter = 0;
} catch (Exception e) {
if (priorImage != null) {
// set this flag to allow image reuse in the video
captureFail = true;
}
rawImage = priorImage;
}
} else {
rawImage = null;
}
}
if (rawImage != null) {
Date timestamp = new Date();
int duration = Math.round((float) (timestamp.getTime() - lastFrameTime.getTime()) * videowriter.getTimeUnits() / 1000f);
if (duration > 0) {
if (image == null) {
image = new BufferedImage(rawImage.width, rawImage.height, BufferedImage.TYPE_INT_RGB);
}
ImageHelper.convertImage(rawImage, image);
if (captureFail) {
overlayMessage(image, rawImage.width, rawImage.height, String.format("Screen Capture Blocked :%d", failCounter++));
captureFail = false;
}
videowriter.writeFrame(image, duration);
lastFrameTime = timestamp;
callSubscriber(image);
}
}
try {
if (deviceManufacturer != null) {
if (deviceManufacturer.contains("htc")) {
// Is it necessary now?
// We would sleep for 1 sec for lower frame rate video on HTC devices via USB bridge
Thread.sleep(1000);
} else {
// Delay for 100 for > 2fps video
Thread.sleep(100);
}
}
} catch (InterruptedException interruptedExp) {
LOGGER.error(interruptedExp.getMessage());
}
} catch (IOException ioExp) {
if (isUSBConnected) {
iExceptionCount++;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
LOGGER.error("Thread Interrupted Exception at LiveScreen Capture: ", e);
}
LOGGER.error("IOException ", ioExp);
}
}
if (iExceptionCount > MAX_FETCH_EXCEPTIONS) {
allDone = true;
LOGGER.error("Too many exceptions caught, now exiting video capture");
}
}
try {
videowriter.close();
} catch (IOException ioExp) {
LOGGER.warn("Exception closing video output stream", ioExp);
}
hasExited = true;
}
}
use of com.android.ddmlib.RawImage in project InspectorClient by zhkl0228.
the class InspectorClient method screenShot.
private static BufferedImage screenShot(IDevice device) throws TimeoutException, AdbCommandRejectedException, IOException {
RawImage rawImage = device.getScreenshot();
// device/adb not available?
if (rawImage == null)
return null;
// convert raw data to an Image
BufferedImage image = new BufferedImage(rawImage.width, rawImage.height, BufferedImage.TYPE_INT_ARGB);
int index = 0;
int indexinc = rawImage.bpp >> 3;
for (int y = 0; y < rawImage.height; y++) {
for (int x = 0; x < rawImage.width; x++) {
int value = rawImage.getARGB(index);
index += indexinc;
image.setRGB(x, y, value);
}
}
return image;
}
use of com.android.ddmlib.RawImage in project android by JetBrains.
the class ScreenshotTask method run.
@Override
public void run(@NotNull ProgressIndicator indicator) {
indicator.setIndeterminate(true);
indicator.setText(AndroidBundle.message("android.ddms.screenshot.task.step.obtain"));
RawImage rawImage;
ScreenshotRetrieverTask retrieverTask = new ScreenshotRetrieverTask(myDevice);
ApplicationManager.getApplication().executeOnPooledThread(retrieverTask);
Future<RawImage> image = retrieverTask.getRawImage();
while (true) {
try {
rawImage = image.get(100, TimeUnit.MILLISECONDS);
break;
} catch (InterruptedException e) {
myError = AndroidBundle.message("android.ddms.screenshot.task.error1", ExceptionUtil.getMessage(e));
return;
} catch (ExecutionException e) {
myError = AndroidBundle.message("android.ddms.screenshot.task.error1", ExceptionUtil.getMessage(e));
return;
} catch (TimeoutException e) {
if (indicator.isCanceled()) {
return;
}
}
}
if (rawImage.bpp != 16 && rawImage.bpp != 32) {
myError = AndroidBundle.message("android.ddms.screenshot.task.error.invalid.bpp", rawImage.bpp);
return;
}
indicator.setText(AndroidBundle.message("android.ddms.screenshot.task.step.load"));
//noinspection UndesirableClassUsage
myImage = new BufferedImage(rawImage.width, rawImage.height, BufferedImage.TYPE_INT_ARGB);
for (int y = 0; y < rawImage.height; y++) {
for (int x = 0; x < rawImage.width; x++) {
int argb = rawImage.getARGB((x + y * rawImage.width) * (rawImage.bpp / 8));
myImage.setRGB(x, y, argb);
}
}
}
use of com.android.ddmlib.RawImage in project VideoOptimzer by attdevsupport.
the class VideoCaptureImplTest method run_test2.
@SuppressWarnings("rawtypes")
@Test
public void run_test2() throws TimeoutException, AdbCommandRejectedException, IOException {
videoCapture.setDevice(device);
RawImage testRaw = new RawImage();
testRaw.data = imagedata;
testRaw.width = 10;
testRaw.height = 10;
testRaw.bpp = 16;
when(device.getScreenshot()).thenReturn(testRaw);
when(videoWriter.getTimeUnits()).thenReturn((int) 1000f);
IVideoImageSubscriber videoImageSub = mock(IVideoImageSubscriber.class);
videoCapture.addSubscriber(videoImageSub);
videoCapture.setDeviceManufacturer("somethingHTC");
doAnswer(new Answer() {
public Object answer(InvocationOnMock invocation) {
((Runnable) invocation.getArguments()[0]).run();
videoCapture.stopRecording();
return null;
}
}).when(threadPool).execute(any(Runnable.class));
videoCapture.run();
assertEquals(0, videoCapture.getiExceptionCount());
assertTrue(videoCapture.isAllDone());
}
Aggregations