Android and MJPEG with java.lang.IllegalArgumentException

I have implemented the demo from the post: Android and MJPEG

But the application always occur error after a while later and I got the exception:

java.lang.IllegalArgumentException: Invalid Unicode sequence: illegal character

within the following code in class MjpegViewThread:


public void run() {
    start = System.currentTimeMillis();
    PorterDuffXfermode mode = new PorterDuffXfermode(PorterDuff.Mode.DST_OVER);
    Bitmap bm;
    int width;
    int height;
    Rect destRect;
    Canvas c = null;
    Paint p = new Paint();
    String fps = "";
    while (mRun)
    {
        if(surfaceDone)
        {
            try
            {
                c = mSurfaceHolder.lockCanvas();
                synchronized (mSurfaceHolder)
                {
                    try
                    {
                        bm = mIn.readMjpegFrame();
                        destRect = destRect(bm.getWidth(),bm.getHeight());
                        c.drawColor(Color.BLACK);
                        c.drawBitmap(bm, null, destRect, p);
                        if(showFps) {
                            p.setXfermode(mode);
                            if(ovl != null) {
                                height = ((ovlPos & 1) == 1) ? destRect.top : destRect.bottom-ovl.getHeight();
                                width  = ((ovlPos & 8) == 8) ? destRect.left : destRect.right -ovl.getWidth();
                                c.drawBitmap(ovl, width, height, null);
                            }
                            p.setXfermode(null);
                            frameCounter++;
                            if((System.currentTimeMillis() - start) >= 1000) {
                                fps = String.valueOf(frameCounter)+"fps";
                                frameCounter = 0; 
                                start = System.currentTimeMillis();
                                ovl = makeFpsOverlay(overlayPaint, fps);
                            }
                        }
                    }
                    catch (IOException e)
                    {
                        Log.i(TAG, "Error: "+e);
                    }
                }
            }
            catch (Exception e)
            {
                Log.i(TAG, "Error: "+e);
            }
            finally
            {
                if (c != null)
                    mSurfaceHolder.unlockCanvasAndPost(c);
            }
        }
    }
}

I am not sure whether the following LogCat information is helpful.


    09-27 17:06:36.645: D/dalvikvm(10120): threadid=9: still suspended after undo (sc=1 dc=1)
    09-27 17:06:46.745: D/dalvikvm(10120): GC_EXTERNAL_ALLOC freed 132K, 47% free 2998K/5575K, external 1625K/2137K, paused 44ms
    09-27 17:06:46.825: D/dalvikvm(10120): GC_EXTERNAL_ALLOC freed 65K, 47% free 2997K/5639K, external 2227K/2779K, paused 27ms
    09-27 17:06:46.955: D/dalvikvm(10120): GC_EXTERNAL_ALLOC freed 127K, 48% free 2997K/5703K, external 2827K/2827K, paused 40ms
    09-27 17:06:47.385: D/dalvikvm(10120): GC_EXTERNAL_ALLOC freed 142K, 48% free 3000K/5703K, external 2827K/2827K, paused 31ms
    09-27 17:06:47.515: D/dalvikvm(10120): GC_EXTERNAL_ALLOC freed 131K, 48% free 2997K/5703K, external 2827K/2827K, paused 27ms
    09-27 17:06:47.615: D/dalvikvm(10120): GC_EXTERNAL_ALLOC freed 127K, 48% free 2997K/5703K, external 2827K/2827K, paused 31ms

Could anyone can give me some clues to solve this problem ?

Answers


I know this is a little old but I found a solution for this problem, the code works perfectly, it is the camera, the FPS is probably set to being "variable" or "auto". I was using a TrendNet TV-IP551WI and the default setting was "auto" for the FPS and I noticed after maybe 5 -15sec the program would crash and I would get that very error, I also noticed that it was very jerky which led me to believe the fps wasn't right. But after setting the fps to a fixed rate (doesn't matter what just choose one, I chose 20) the error should go away and it shouldn't spaz out anymore.


You might want to try neuralassembly's code for mjpegview as a new dummy project. It's the same code but with added enhancement. I've had same problem then tried his code with some adjustment, and it works like a charm.

Plus, if you encountered ndk_project_path=null while gradle is building, add this chunk of codes below in build.gradle inside the android tag:

buildTypes {
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}
sourceSets.main {
    jni.srcDirs = []
    jniLibs.srcDir 'src/main'
}

Hope this helps other people.


Need Your Help

Url rewrite difficulty

php apache .htaccess nginx rewrite

What I want to achieve is, if direct path doesn't exist then rewrite to index.php. Here is how it looks in apache syntax

How to make Travis CI to install Python dependencies declared in tests_require?

python testing travis-ci setup.py

I have Python package with setup.py. It has regular dependencies declared in install_requires and development dependencies declared in tests_require, e.g. flake8.