I am working on streaming a video from web. Where I decode the video/
audio stuff in native code and get the raw pixels for video

I create a bitmap in java code, with surfaceholder and canvas and
update pixels for each bitmap from native code and then stream the
bitmaps as video. My problem here is, the video crashes after a few
seconds because of low memory.

I want to know whether there is anything that i need to make sure to
not to crash app and use low memory.

Here is my code.

public CanvasThread(SurfaceHolder surfaceHolder, Panel panel) {
        _surfaceHolder = surfaceHolder;
        _panel = panel;     }
    public void setRunning(boolean run) {
        _run = run;    }

    @Override
    public void run() {
        Canvas c;
        while (_run) {
            c = null;
            try {
                c = _surfaceHolder.lockCanvas(null);
                synchronized (_surfaceHolder) {
                    _panel.onDraw(c);
                }
            } finally {
                    if (c != null) {
                    _surfaceHolder.unlockCanvasAndPost(c);
                }
           }

public class Panel extends SurfaceView implements
SurfaceHolder.Callback{
                private CanvasThread canvasthread;
                private static Bitmap mBitmap;
                private static boolean ii=false;
               public Panel(Context context, AttributeSet attrs) {
                        super(context, attrs);
                getHolder().addCallback(this);
                    canvasthread = new CanvasThread(getHolder(), this);
                    setFocusable(true);

                }

                 public Panel(Context context) {
                           super(context);
                            getHolder().addCallback(this);
                            canvasthread = new CanvasThread(getHolder(), this);
                            setFocusable(true);
                    }

                 private static native void renderbitmap(Bitmap bitmap); 
//native
function
                @Override
                public void onDraw(Canvas canvas) {
                        mBitmap=Bitmap.createBitmap(480, 320, 
Bitmap.Config.RGB_565);
                        renderbitmap(mBitmap); //Update pixels from native code
                        canvas.drawBitmap(mBitmap, 0,0,null);
        }

                @Override
                public void surfaceChanged(SurfaceHolder holder, int format, int
width,int height) {             }
                @Override
                public void surfaceCreated(SurfaceHolder holder) {
                    canvasthread.setRunning(true);
                    canvasthread.start();               }
                @Override
                public void surfaceDestroyed(SurfaceHolder holder) {
                        boolean retry = true;
                        canvasthread.setRunning(false);
                        while (retry) {
                                try {
                                        canvasthread.join();
                                        retry = false;
                                } catch (InterruptedException e) {              
                }
                }

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

Reply via email to