Reputation: 73
All right, I'm at my wit's end. I'm writing a droid app that receives preview data, processes it, and then displays the altered data to the screen. So far so good -- except for the fact that after some indeterminate amount of time (usually a minute or two) the YUV data that comes in during the onPreviewFrame callback is...rolled...horizontally. I captured the raw yuv to the sd card:
[looks like I can't post pictures here yet, so here's the url: raw yuv capture]
This is my first droid app, but I've spent a lot of time working on various desktop video software. The thing that immediately came to mind when I saw this was that I had a thread synchronization problem, and the buffer was getting overwritten in some strange way because of it.
And my code did use a worker thread initially. So to eliminate this possibility that the issue was thread-releated, I took the worker thread out and put everything inside of onPreviewFrame. Again, the same problem: skewed YUV data.
Then I did some googling and discovered that heavy processing inside of onPreviewFrame could result in random weirdness. To circumvent that, I changed my callback to the OneShot variety, which resulted in the code I'm using now:
public void surfaceCreated(SurfaceHolder holder) {
Log.i(TAG, "surfaceCreated");
mCamera = Camera.open();
mCamera.setOneShotPreviewCallback(new PreviewCallback() {
public void onPreviewFrame(byte[] data, Camera camera) {
Canvas canvas = mHolder.lockCanvas();
try
{
Bitmap bmp = processFrame(data);
if (bmp != null) {
if (canvas != null) {
canvas.drawBitmap(bmp, (canvas.getWidth() - getFrameWidth()) / 2, (canvas.getHeight() - getFrameHeight()) / 2, null);
}
bmp.recycle();
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
mHolder.unlockCanvasAndPost(canvas);
mCamera.setOneShotPreviewCallback(this);
}
}
});
}
Unfortunately, I still get the skewed yuv data.
My testing device is an HTC EVO 4G. I know this phone has its issues, but I'm wary to chalk this up to a hardware bug just yet, mainly because I'm almost certain it's due to programmer error. Problem is, I've pared my code down to the bone, and the problem is still manifesting.
Has anybody encountered this before?
Upvotes: 3
Views: 1251
Reputation: 73
Well, it looks like it's an issue with HTC phones. This is the exact problem I'm having. Over here they say it's caused by the rear camera lens coming loose and the solution is to push it in hard with your thumb for a few seconds to reseat it.
Not a software problem after all.
Upvotes: 3