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 ?