我添加了使用CameraInfo
选择相机的代码,因为仅添加Camera.open()
无效HTC devices
而我将holder
中的mCamera.setPreviewDisplay(holder)
更改为{{ 1}}这是一个实例变量。
我尝试在一个Activity的mHolder
中打开自定义Camera,在logcat输出中我注意到代码在onResume
之后进入surfaceChanged
因为那是我设置的地方使用surfaceCreated
的相机预览尺寸,然后它似乎无法分配内存:Parameters
(我的设备上的内存很少 ~2.47GB 可用空间)错了,因为那个。
我收到以下巨大的未知错误,您可以查看我的CameraActivity和我的CameraPreview:
GenericAlloc: Failed to allocate device memory
这是我的横向XML:
CameraClient(127): Opening camera 0
CameraHAL(127): camera_device open
CameraHAL(127): Adapter state switch PREVIEW_ACTIVE Invalid Op! event = 0xf
CameraPreview(4660): Camera Preview size set to 1920X1080
IMGSRV(127): :0: gralloc_unregister_buffer: Cannot unregister a locked buffer (ID=2100)
GraphicBufferMapper(127): unregisterBuffer(0x400a7470) failed -22 (Invalid argument)
IMGSRV(127): :0: gralloc_unregister_buffer: Cannot unregister a locked buffer (ID=2102)
GraphicBufferMapper(127): unregisterBuffer(0x458372f8) failed -22 (Invalid argument)
IMGSRV(127): :0: gralloc_unregister_buffer: Cannot unregister a locked buffer (ID=2104)
GraphicBufferMapper(127): unregisterBuffer(0x40d5ffd8) failed -22 (Invalid argument)
IMGSRV(127): :0: gralloc_unregister_buffer: Cannot unregister a locked buffer (ID=2106)
GraphicBufferMapper(127): unregisterBuffer(0x40d5fa90) failed -22 (Invalid argument)
CameraHAL(127): Adapter state switch PREVIEW_ACTIVE Invalid Op! event = 0xf
Surface(127): getSlotFromBufferLocked: unknown buffer: 0x400a7470
CameraHAL(127): cancel_buffer() failed: Invalid argument (22)
IMGSRV(127): :0: gralloc_module_unlock: Buffer is already unlocked
GraphicBufferMapper(127): unlock(...) failed -22 (Invalid argument)
Surface(127): getSlotFromBufferLocked: unknown buffer: 0x400a7470
CameraHAL(127): cancel_buffer() failed: Invalid argument (22)
dalvikvm(4660): GC_FOR_ALLOC freed 183K, 3% free 9939K/10160K, paused 24ms, total 24ms
CameraPreview(4660): Camera Preview size set to 1920X1080
IMGSRV(124): :0: PVRSRVAllocDeviceMem: Error 1 returned
IMGSRV(124): :0: GenericAlloc: Failed to allocate device memory
GraphicBufferAllocator(124): alloc(1952, 1128, 256, 00000b02, ...) failed -12 (Out of memory)
GraphicBufferAllocator(124): Allocated buffers:
GraphicBufferAllocator(124): 0x40027f90: 276.00 KiB | 720 ( 736) x 96 | 5 | 0x00000b00
GraphicBufferAllocator(124): 0x4002f5e0: unknown | 1952 (4096) x 1128 | 100 | 0x00000b02
GraphicBufferAllocator(124): 0x40e30f18: 143.75 KiB | 720 ( 736) x 50 | 5 | 0x00000b00
GraphicBufferAllocator(124): 0x40eb8580: unknown | 1952 (4096) x 1128 | 100 | 0x00000b02
GraphicBufferAllocator(124): 0x40ebc7f0: 3680.00 KiB | 720 ( 736) x 1280 | 1 | 0x00000933
GraphicBufferAllocator(124): 0x40ebdeb8: unknown | 1952 (4096) x 1128 | 100 | 0x00000b02
GraphicBufferAllocator(124): 0x40ebf0f0: 3404.00 KiB | 720 ( 736) x 1184 | 5 | 0x00000b00
GraphicBufferAllocator(124): 0x40ec3cb8: unknown | 1952 (4096) x 1128 | 100 | 0x00000b02
GraphicBufferAllocator(124): 0x40f1ca58: 3404.00 KiB | 720 ( 736) x 1184 | 5 | 0x00000b00
GraphicBufferAllocator(124): 0x40f1dd60: 3404.00 KiB | 720 ( 736) x 1184 | 5 | 0x00000b00
GraphicBufferAllocator(124): 0x40f807e8: 3404.00 KiB | 720 ( 736) x 1184 | 5 | 0x00000b00
GraphicBufferAllocator(124): 0x412e9048: 5120.00 KiB | 720 (1024) x 1280 | 5 | 0x00001a00
GraphicBufferAllocator(124): 0x412e90d8: 5120.00 KiB | 720 (1024) x 1280 | 5 | 0x00001a00
GraphicBufferAllocator(124): 0x41327178: 143.75 KiB | 720 ( 736) x 50 | 5 | 0x00000b00
GraphicBufferAllocator(124): 0x41329d28: 3680.00 KiB | 720 ( 736)
(124): GraphicBufferAlloc::createGraphicBuffer(w=1952, h=1128) failed (Out of memory), handle=0x0
BufferQueue(124): [SurfaceView] dequeueBuffer: SurfaceComposer::createGraphicBuffer failed
CameraHAL(127): dequeueBuffer failed: Out of memory (12)
IMGSRV(127): :0: gralloc_module_unlock: Buffer is already unlocked
GraphicBufferMapper(127): unlock(...) failed -22 (Invalid argument)
BufferQueue(124): [SurfaceView] cancelBuffer: slot 3 is not owned by the client (state=0)
IMGSRV(127): :0: gralloc_module_unlock: Buffer is already unlocked
GraphicBufferMapper(127): unlock(...) failed -22 (Invalid argument)
BufferQueue(124): [SurfaceView] cancelBuffer: slot 1 is not owned by the client (state=0)
CameraHAL(127): Error occurred, performing cleanup
CameraHAL(127): AppCallbackNotifier received error -12
CameraHAL(127): AppCallbackNotifier mNotifyCb -12
dalvikvm(586): GC_CONCURRENT freed 616K, 8% free 10610K/11532K, paused 6ms+7ms, total 45ms
dalvikvm(586): WAIT_FOR_CONCURRENT_GC blocked 21ms
dalvikvm(586): WAIT_FOR_CONCURRENT_GC blocked 20ms
EsService(9002): readResults: read results: 2, lastRequestId: 12
dalvikvm(5174): GC_CONCURRENT freed 561K, 21% free 9210K/11564K, paused 3ms+3ms, total 24ms
ActivityManager(379): Process com.android.launcher (pid 8391) has died.
dalvikvm(9002): GC_CONCURRENT freed 2856K, 10% free 27486K/30376K, paused 3ms+8ms, total 49ms
libEGL(9002): loaded /vendor/lib/egl/libEGL_POWERVR_SGX540_120.so
libEGL(9002): loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so
libEGL(9002): loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX540_120.so
ActivityManager(379): Launch timeout has expired, giving up wake lock!
ActivityManager(379): Activity idle timeout for ActivityRecord{429176f8 u0 com.blutechnologies.scancard/.CameraActivity}
dalvikvm(586): GC_CONCURRENT freed 612K, 9% free 10604K/11532K, paused 4ms+4ms, total 39ms
dalvikvm(586): WAIT_FOR_CONCURRENT_GC blocked 19ms
dalvikvm(586): GC_CONCURRENT freed 604K, 9% free 10502K/11532K, paused 3ms+3ms, total 48ms
WindowManager(379): Screenshot Window{421c84f0 u0
com.blutechnologies.scancard/com.blutechnologies.scancard.CameraActivity} was all
black! mSurfaceLayer=21050 minLayer=21015 maxLayer=21050
dalvikvm(487): GC_FOR_ALLOC freed 2272K, 25% free 23405K/31048K, paused 37ms, total 37ms
ActivityManager(379): START u0
{act=com.android.systemui.recent.action.TOGGLE_RECENTS flg=0x10800000
cmp=com.android.systemui/.recent.RecentsActivity (has extras)} from pid 487
dalvikvm(379): GC_FOR_ALLOC freed 3773K, 25% free 27472K/36180K, paused 92ms, total 92ms
dalvikvm(487): GC_FOR_ALLOC freed 781K, 21% free 24624K/31048K, paused 23ms, total 23ms
ActivityManager(379): Activity pause timeout for ActivityRecord{429176f8 u0
com.blutechnologies.scancard/.CameraActivity}
ActivityManager(379): Process com.google.android.apps.magazines (pid 8851) has died.
ActivityManager(379): Activity stop timeout for ActivityRecord{4290f880 u0
com.blutechnologies.scancard/.MainActivity}
ActivityManager(379): Activity stop timeout for ActivityRecord{429176f8 u0
com.blutechnologies.scancard/.CameraActivity}
ActivityManager(379): Activity reported stop, but no longer stopping:
ActivityRecord{429176f8 u0 com.blutechnologies.scancard/.CameraActivity}
InputDispatcher(379): Application is not responding: Window{421c84f0 u0
com.blutechnologies.scancard/com.blutechnologies.scancard.CameraActivity}. It has
been 5019.4ms since event, 5003.4ms since wait started. Reason: Waiting because
the touched window has not finished processing the input events that were
previously delivered to it.
WindowManager(379): Input event dispatching timed out sending to
com.blutechnologies.scancard/com.blutechnologies.scancard.CameraActivity
Process(379): Sending signal. PID: 4660 SIG: 3
dalvikvm(4660): threadid=3: reacting to signal 3
dalvikvm(4660): Wrote stack traces to '/data/anr/traces.txt'
Process(379): Sending signal. PID: 379 SIG: 3
dalvikvm(379): threadid=3: reacting to signal 3
dalvikvm(379): Wrote stack traces to '/data/anr/traces.txt'
Process(379): Sending signal. PID: 487 SIG: 3
dalvikvm(487): threadid=3: reacting to signal 3
Process(379): Sending signal. PID: 606 SIG: 3
dalvikvm(606): threadid=3: reacting to signal 3
dalvikvm(606): Wrote stack traces to '/data/anr/traces.txt'
Process(379): Sending signal. PID: 613 SIG: 3
dalvikvm(613): threadid=3: reacting to signal 3
dalvikvm(613): Wrote stack traces to '/data/anr/traces.txt'
dalvikvm(487): Wrote stack traces to '/data/anr/traces.txt'
dalvikvm(379): GC_EXPLICIT freed 3869K, 24% free 27763K/36180K, paused 3ms+9ms,
total 103ms
Process(379): Sending signal. PID: 3927 SIG: 3
dalvikvm(3927): threadid=3: reacting to signal 3
dalvikvm(3927): Wrote stack traces to '/data/anr/traces.txt'
ActivityManager(379): ANR in com.blutechnologies.scancard
(com.blutechnologies.scancard/.CameraActivity)
ActivityManager(379): Reason: keyDispatchingTimedOut
ActivityManager(379): Load: 1.56 / 1.66 / 1.5
ActivityManager(379): CPU usage from 6021ms to 0ms ago:
ActivityManager(379): 11% 379/system_server: 7.5% user + 3.5% kernel / faults:
910 minor 6 major
ActivityManager(379): 7.1% 124/surfaceflinger: 5.6% user + 1.4% kernel / faults:
101 minor
ActivityManager(379): 1.1% 8983/kworker/u:5: 0% user + 1.1% kernel
ActivityManager(379): 1% 5754/kworker/u:2: 0% user + 1% kernel
ActivityManager(379): 0.6% 127/mediaserver: 0% user + 0.6% kernel
ActivityManager(379): 0.6% 7324/kworker/u:4: 0% user + 0.6% kernel
ActivityManager(379): 0.5% 487/com.android.systemui: 0.3% user + 0.1% kernel /
faults: 1 minor
ActivityManager(379): 0.5% 9030/kworker/0:0: 0% user + 0.5% kernel
ActivityManager(379): 0.3% 117/vold: 0% user + 0.3% kernel
ActivityManager(379): 0.3% 3927/com.whatsapp: 0.3% user + 0% kernel
ActivityManager(379): 0.1% 82/mmcqd/0: 0% user + 0.1% kernel
ActivityManager(379): 0.1% 95/ueventd: 0% user + 0.1% kernel
ActivityManager(379): 0% 108/irq/206-mms_ts: 0% user + 0% kernel
ActivityManager(379): 0.1% 121/netd: 0.1% user + 0% kernel
ActivityManager(379): 0% 443/wpa_supplicant: 0% user + 0% kernel
ActivityManager(379): 0.1% 586/com.google.process.location: 0.1% user + 0% kernel
/ faults: 1 minor
ActivityManager(379): 0.1% 7385/com.example.newcontactlayout: 0.1% user + 0%
kernel / faults: 1 minor
ActivityManager(379): 12% TOTAL: 6.8% user + 5% kernel + 0.1% iowait
ActivityManager(379): CPU usage from 1386ms to 1904ms later with 99% awake:
ActivityManager(379): 5.6% 379/system_server: 3.7% user + 1.8% kernel / faults:
11 minor
ActivityManager(379): 5.6% 395/ActivityManager: 1.8% user + 3.7% kernel
ActivityManager(379): 1.8% 385/Compiler: 1.8% user + 0% kernel
ActivityManager(379): 1.8% 391/SensorService: 0% user + 1.8% kernel
ActivityManager(379): 1.8% 406/UEventObserver: 1.8% user + 0% kernel
ActivityManager(379): 1.3% 3927/com.whatsapp: 0% user + 1.3% kernel
ActivityManager(379): 3.8% TOTAL: 1.9% user + 1.9% kernel
ActivityManager(379): Launch timeout has expired, giving up wake lock!
ActivityManager(379): Activity idle timeout for ActivityRecord{429176f8 u0
com.blutechnologies.scancard/.CameraActivity}
这是我的纵向XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<FrameLayout android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
/>
<com.blutechnologies.scancard.ShutterButton android:id="@+id/btn_capture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/btn_capture"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
/>
</RelativeLayout>
现在看起来似乎没有任何东西可以连接到相机,甚至没有连接到默认的相机应用程序。为什么会发生错误,我该如何解决?
这似乎是一个怪异的事情,我关掉手机并重新打开它,它似乎工作正常。另一个原因可能是在 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<FrameLayout android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
/>
<com.blutechnologies.scancard.ShutterButton android:id="@+id/btn_capture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/btn_capture"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
调用此代码:
surfaceDestroyed