Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4004462
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:16:35+00:00 2026-05-20T08:16:35+00:00

I am working on streaming a video from web. Where I decode the video/audio

  • 0

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);
       mBitmap=Bitmap.createBitmap(480, 320, Bitmap.Config.RGB_565);//bitmap created in constructor
    }

     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) {

        renderbitmap(mBitmap); //Update pixels from native code
        canvas.drawBitmap(mBitmap, 0,0,null);//draw on canvas
}

    @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) {              }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T08:16:36+00:00Added an answer on May 20, 2026 at 8:16 am

    You might check out Richard Quirk’s glbuffer. I’m using it in a video player app.

    In general you want to hold on to the video packets you’re receiving and only decode them right before they are needed for display. It should be easy to integrate your code with glbuffer and bypass any Bitmap allocation in Java code.

    There would be one decoded frame at any given time present in the native code and in GL texture memory and several encoded packets that you’re keeping around for buffering.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on streaming a song from the web. I have made the
I am running the following code to capture the live video streaming from an
I am working on video streaming for iPhone. The case is i get data
I am working on a web app that needs to display streaming video of
I'm using this code for video streaming, and it's working fine. When a song
I have smooth streaming working on my local machine. The video plays nicely and
I am working on a streaming download (CSV) from Rails 3.2 and am coming
I'm working on a streaming audio player for Linux/OS X with a bizarre use
I am desperate to get a streaming CSV download working in my Rails 3.2.2
i'm working with Flash Live Encoder. It's using camera for streaming video. Support forum

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.