I am writing a program to study Android Camera functions. Now, I have some problems about Camera preview operation:
My program will create a surfaceview object in the main activity (ActivityMain)'s onCreate() function and then set it to the content.
super.onCreate(savedInstanceState);
m_surface = new MyCameraSurface(this);
// remove title bar
requestWindowFeature(Wind开发者_如何学Goow.FEATURE_NO_TITLE);
setContentView(m_surface);
Then startPreview() will be called when surfaceChanged() is running.
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
Log.d(TAG, "*** surfaceChanged >>>>> ***");
Log.d(TAG, "format=" + format + ", width=" + width + ", height=" + height);
if(m_control.IsCameraClosed() == false) {
if(m_control.IsPreviewRun() == false) {
m_control.startPreview();
}
}
Log.d(TAG, "*** surfaceChanged <<<<< ***");
}
My problem is: at the beginning my program always receives "GetNextPreviewFrame Error/1 frame:0x0, buffer:0x0" error:
07-22 06:47:46.727: DEBUG/MyCameraSurface(2313): *** surfaceChanged <<<<< ***
07-22 06:47:46.735: DEBUG/SurfaceFlinger(1276): commiting overlay changes
07-22 06:47:46.735: INFO/TIOverlay(1276): Nothing to do!
07-22 06:47:46.735: INFO/ActivityManager(1276): Displayed activity com.hykwok.CameraEffect/.ActivityMain: 7866 ms (total 7866 ms)
07-22 06:47:47.792: ERROR/CameraHal(1052): GetNextPreviewFrame Error/1 frame:0x0, buffer:0x0
07-22 06:47:48.477: DEBUG/dalvikvm(1276): GC freed 2299 objects / 119216 bytes in 143ms
07-22 06:47:48.793: ERROR/CameraHal(1052): GetNextPreviewFrame Error/1 frame:0x0, buffer:0x0
07-22 06:47:49.794: ERROR/CameraHal(1052): GetNextPreviewFrame Error/1 frame:0x0, buffer:0x0
07-22 06:47:50.794: ERROR/CameraHal(1052): GetNextPreviewFrame Error/1 frame:0x0, buffer:0x0
However, when I switch to another activity (ActivityCameraSetting) and then go back to the main activity, the output becomes normal.
Could anyone give some suggestion to me to fix it?
I am using Motorola Milestone. Firmware version is 2.1-update1 and build number is SHOLS_U2.02.36.0.
I am not sure other Android phones whether have this problem or not.
Another question is: Is it possible to get preview frame data by the preview callback function without set surfaceview holder?
Thank you for your help.
Source codes can be downloaded from here:
Source codes link
Hard to tell exactly what the issue is without more of the logs, I would guess based on the 0x0 bit that either your surface isn't fully created yet or the camera preview size isn't set properly. One suggestion I would have is to add:
m_holder.setFormat(PixelFormat.OPAQUE);
to your MyCameraSurface constructor. I was getting some similarly ambiguous errors re: CameraHal and that seemed to resolve the bulk of them. Can you post a bit more of your logs?
精彩评论