Tuesday, December 8, 2009

[android-developers] Re: Camera Preview Filter Choppiness

You're right, rollback... i didn't even notice that.

Although the threads are a one-shot processing and end immediately
after that, the system may start to choke on the sheer multitude of
them, especially if the decoding is a bit slow.

Greg, create only one thread and pause and resume the thread when
necessary.
Use the ExecutorService - spawning Futures - (java.util.concurrent
package) for that if you don't want to write your own concurrency and
synchronization implementation.

On Dec 7, 6:05 pm, rollbak <roll...@gmail.com> wrote:
> That's right, and also you are spawning new threads in every preview
> frame. And last but not least, i don't think having two surfaceview
> stacked is a good solution, at least is not intended for using it that
> way.
>
> On Dec 7, 2:10 pm, Streets Of Boston <flyingdutc...@gmail.com> wrote:
>
>
>
> > How fast is 'decodeYUV' method? You call this method while your canvas
> > is locked.
> > If 'decodeYUV' is slow, it not only makes your background thread
> > sluggish, but your main GUI-thread as well, because the canvas is
> > locked for too long.
>
> > Also, you don't synchronize on '_data'... Your implementation of
> > 'onPreviewFrame' is filling '_data' and your background thread is
> > reading it. The filling(=arraycopy) of '_data' may not be finished
> > before your it's being read by your background thread.
>
> > On Dec 5, 9:41 pm, Greg <madma...@gmail.com> wrote:
>
> > > Hello,
> > > I've been working on creating a program that will output the Camera
> > > Preview with various user-chosen filters (SnapPhoto has this
> > > functionality) and I've run into some problems.
>
> > > I have the following set up.
> > > - Camera preview set to a SurfaceView (I had to set PUSH_BUFFERS or
> > > the program fails).
> > > - Have another SurfaceView lieing over the Camera preview SurfaceView
> > > (in a FrameLayout)
> > > - Registered a camera callback for the preview data
>
> > > My problem is that the output is extremely choppy and the program
> > > quickly becomes unresponsive. I've set up a thread to do the
> > > processing, but this doesn't seem to help. I've implemented the
> > > decoding (into rgb_8888) algorithm (courtesy of dmanpearlhttp://groups.google.com/group/android-developers/msg/d3b29d3ddc8abf9b
> > > ) Is there anything I'm doing blatantly wrong or something I could fix
> > > to make this program run at a decent speed? Sorry if the code has poor
> > > style, I'm sort of an Android beginner and, for that matter, Java
> > > beginner.
>
> > > This code is inside the second SurfaceView, lieing over the Camera
> > > preview SurfaceView
>
> > > public void onPreviewFrame(byte[] data, Camera camera) {
> > >                 if(hasSurface) {
> > >                                 System.arraycopy(data, 0, _data, 0, data.length);
> > >                                 outputThread = new HandleOutput();
> > >                                 outputThread.start();
> > >                 }
> > >         }
>
> > > where HandleOutput() extends Thread, and _data is a global array.
>
> > > and this is inside the Thread
>
> > > public void run() {
> > >                         while(!done) {
> > >                                 canvas = mHolder.lockCanvas();
> > >                                 PixelManip.decodeYUV(rgb, _data, width, height); //courtesy of
> > > dmanpearl (link above)
> > >                                 PixelManip.applyFilter(filterID, _data, rgb);
> > >                                 bitmap.setPixels(rgb, 0, width, 0, 0, width, height);
> > >                                 canvas.drawBitmap(bitmap, 0, 0, paint);
> > >                                 mHolder.unlockCanvasAndPost(canvas);
> > >                                 done = true;
> > >                         }
> > >                 }
>
> > > Thanks,
> > > Greg
>
> > > P.S. Let me know if I should post any more code.- Hide quoted text -
>
> - Show quoted text -

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate