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 6038107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:10:14+00:00 2026-05-23T06:10:14+00:00

I am creating a live streaming app, but I’m stuck at a certain point.

  • 0

I am creating a live streaming app, but I’m stuck at a certain point.
So, this is my code:

public synchronized byte[] getPicture(int Width, int Height) {
    FrameWidth = Width;
    FrameHeight = Height;

    try {                           
        while (!isPreviewOn) {
            wait();
        }

        isDecoding = true;
        mAvailableFrame = false;

        c.setOneShotPreviewCallback(mPreviewCallback);                

        while (isDecoding) {
            wait();
        }

    }
    catch (Exception e) {   
        return null;
    }

    mAvailableFrame = false;

    return mCurrentFrame;
}

PreviewCallback mPreviewCallback = new PreviewCallback() {

    @Override
    public synchronized void onPreviewFrame(byte[] data, Camera camera) {
        int width = FrameWidth;
        int height = FrameHeight;

        // API 7
        int[] temp = new int[width*height];
        OutputStream out = new ByteArrayOutputStream();
        Bitmap bm = null;

        raw2jpg(temp, data, width, height);
        bm = Bitmap.createBitmap(temp, width, height, Bitmap.Config.RGB_565);
        bm.compress(CompressFormat.JPEG, 100, out);
        /*ref*/mCurrentFrame = ((ByteArrayOutputStream)out).toByteArray();
        mAvailableFrame = true;
        isDecoding = false;
        notify();                   
    }
};

When synchronised getPicture() is called, while it is executing no other thread can call a synchronised method on that instance. While getPicture() is waiting for isDecoding it is holding a lock on the instance. I suspect setOneShotPreviewCallback() is executing and that the camera is trying to call onPreviewFrame() on its own thread but as that is also a synchronised method it blocks waiting for getPicture() to terminate which it can’t as it needs the callback to clear isDecoding. It looks like a deadlock situation.

It can’t call onPreviewFrame because the object instance is locked so the camera thread is blocked waiting for getPicture() to complete.

Am I correct?
And how should I fix this? So I have to notify OnPreviewFrame again that IsDecoding = false

Any help is very much appreciated.

Also vote this up and I will give a bounty 😉

  • 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-23T06:10:15+00:00Added an answer on May 23, 2026 at 6:10 am

    The notify() in mPreviewCallback.onPreviewFrame() notifies the mPreviewCallback object monitor, while wait() in getPicture() waits on another object monitor – notify will never release wait(). You should define a (final) variable accessible from both objects and call wait() and notify() explicitly on that variable. Something like this:

    public final Object myMonitor = new Object();
    
    public synchronized byte[] getPicture(int Width, int Height) {
        FrameWidth = Width;
        FrameHeight = Height;
    
        try {                     
            synchronized(myMonitor) {    
                while (!isPreviewOn) {
                    myMonitor.wait();
                }
            }
            isDecoding = true;
            mAvailableFrame = false;
    
            c.setOneShotPreviewCallback(mPreviewCallback);                
    
            synchronized(myMonitor) {    
                while (isDecoding) {
                    myMonitor.wait();
                }
            }
        }
        catch (Exception e) {   
            return null;
        }
    
        mAvailableFrame = false;
    
        return mCurrentFrame;
    }
    
    PreviewCallback mPreviewCallback = new PreviewCallback() {
    
        @Override
        public synchronized void onPreviewFrame(byte[] data, Camera camera) {
            int width = FrameWidth;
            int height = FrameHeight;
    
            // API 7
            int[] temp = new int[width*height];
            OutputStream out = new ByteArrayOutputStream();
            Bitmap bm = null;
    
            raw2jpg(temp, data, width, height);
            bm = Bitmap.createBitmap(temp, width, height, Bitmap.Config.RGB_565);
            bm.compress(CompressFormat.JPEG, 100, out);
            /*ref*/mCurrentFrame = ((ByteArrayOutputStream)out).toByteArray();
            mAvailableFrame = true;
            isDecoding = false;
            synchronized(myMonitor) {    
                myMonitor.notify();                   
            }
        }
    };
    

    I don’t know the API you are extending, but probably the processes won’t need to be synchronized after this change. Also, it is not clear who is setting isPreviewOn.

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

Sidebar

Related Questions

I'm creating a live streaming app, but I have an issue on which media
I have created an app capable of live streaming, but I currently have no
I'm creating an app that in addition to the live production environment requires a
I've got this: $(.TempAddLineItem).live('click', function() { var $this = $(this); $(this).closest(tr).append(<tr><td>row creating</td></tr>); //$(this).append(<tr><td>row creating</td></tr>);
I'm using jquery and creating event handlers like this: $('#some_selector a.add').live('click', function(){...}); However, I
Im creating a customised wallpaper service(LIVE WALLPAPER)... I integrated it with another code section
I am creating a web app that requires a live notification system. How would
Creating a view with following code. - (void)loadView { paintView=[[UIView alloc]initWithFrame:CGRectMake(0, 50, 320, 430)];
Creating Traversals for Binary Search Tree with Recursion. void inOrder(void (*inOrderPtr)(T&)) { if(this->left !=
(creating a separate question after comments on this: Javascript redeclared global variable overrides old

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.