Slow behavior in Emulator, how to recreate it:CameraPreview

Common bugs/problems with the Android SDK the Emulator and the ADT-Plugin.

Slow behavior in Emulator, how to recreate it:CameraPreview

Postby franco » Fri Apr 04, 2008 3:18 pm

Hi,
Using the CameraPreview example and doing some image processing I
found a strange slow behavior in the Emulator. I have little
experience with java and Android (C/C++ background) so I do not know
if it is a true issue of the emulator or some strange memory/thread
handling that I am not aware.

When the application starts after the emulator starts, the application
is very slow (228 ms per frame).
If I press the "Back" button and then press the application icon, The
applications is about 4 times faster (64ms per frame).

This fast framerate will continue to work and will not go back to the
slow behavior.
I tried launching the emulator from Eclipse and stand alone. Also in
Windows and OSX and the behavior is always the same and happens every
time.

To recreate the slow behavior I just added a couple of lines (intense
CPU usage) to the CameraPreview sample provided by the SDK.The
modified run() part is:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         @Override
  2.  
  3.                 public void run() {
  4.  
  5.             // We first open the CameraDevice and configure it.
  6.  
  7.             CameraDevice camera = CameraDevice.open();
  8.  
  9.             if (camera != null) {
  10.  
  11.                 CameraDevice.CaptureParams param = new
  12.  
  13. CameraDevice.CaptureParams();
  14.  
  15.                     param.type = 1; // preview
  16.  
  17.                     param.srcWidth      = 1280;
  18.  
  19.                     param.srcHeight     = 960;
  20.  
  21.                     param.leftPixel     = 0;
  22.  
  23.                     param.topPixel      = 0;
  24.  
  25.                     param.outputWidth   = 320;
  26.  
  27.                     param.outputHeight  = 240;
  28.  
  29.                     param.dataFormat    = 2; // RGB_565
  30.  
  31.                 camera.setCaptureParams(param);
  32.  
  33.             }
  34.  
  35.  
  36.  
  37.             // This is our main acquisition thread's loop, we go until
  38.  
  39.             // asked to quit.
  40.  
  41.             SurfaceHolder holder = mHolder;
  42.  
  43.  
  44.  
  45.                 //
  46.  
  47. ===========================================================
  48.  
  49.                 // Added to check strange behavior
  50.  
  51.                 //
  52.  
  53. ===========================================================
  54.  
  55.                         long timeMillis = java.lang.System.currentTimeMillis();
  56.  
  57.                         Paint paint = new Paint();
  58.  
  59.                         paint.setTextSize(20);
  60.  
  61.                         paint.setARGB(255, 255, 0, 0);
  62.  
  63.  
  64.  
  65.             while (!mDone) {
  66.  
  67.                 // Lock the surface, this returns a Canvas that can
  68.  
  69.                 // be used to render into.
  70.  
  71.                 Canvas canvas = holder.lockCanvas();
  72.  
  73.  
  74.  
  75.                 // Capture directly into the Surface
  76.  
  77.                 if (camera != null) {
  78.  
  79.                     camera.capture(canvas);
  80.  
  81.  
  82.  
  83.                         //
  84.  
  85. ===========================================================
  86.  
  87.                         // Added to check strange behavior
  88.  
  89.                         //
  90.  
  91. ===========================================================
  92.  
  93.                     int b=3;
  94.  
  95.                     for(int i=0; i<100000; i++)
  96.  
  97.                         b=b+1;
  98.  
  99.  
  100.  
  101.                                 long timeNew = java.lang.System.currentTimeMillis();
  102.  
  103.                                 canvas.drawText("ms=" + (timeNew - timeMillis), 10, 20,
  104.  
  105. paint);
  106.  
  107.                                 timeMillis = timeNew;
  108.  
  109.                 }
  110.  
  111.  
  112.  
  113.                 // And finally unlock and post the surface.
  114.  
  115.                 holder.unlockCanvasAndPost(canvas);
  116.  
  117.             }
  118.  
  119.  
  120.  
  121.             // Make sure to release the CameraDevice
  122.  
  123.             if (camera != null)
  124.  
  125.                 camera.close();
  126.  
  127.         }
Parsed in 0.040 seconds, using GeSHi 1.0.8.4


Can someone test it and see if the results are the same? Any ideas?
Thanks
Franco
franco
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Apr 04, 2008 3:12 pm

Top

Return to SDK/ADT/Emulator Problems

Who is online

Users browsing this forum: No registered users and 7 guests