当前位置: 代码迷 >> Android >> 安卓Surface渲染异常记录
  详细解决方案

安卓Surface渲染异常记录

热度:19   发布时间:2016-04-27 23:43:06.0
安卓Surface渲染错误记录
Surface显示参照源码
frameworks\av\media\libstagefright\colorconversion
frameworks\av\services\camera\libcameraservice
frameworks\native\services\surfaceflinger
frameworks\native\libs\gui

1、setBufferCount failure
native_window_set_buffer_count调用失败,该mNativeWindow已无法使用,确认是否已被销毁
E/BufferQueue( 2188): [SurfaceView] setBufferCount: BufferQueue has been abandoned!
E/Surface (11666): IGraphicBufferProducer::setBufferCount(10) returned No such device

native_window_set_buffer_count调用失败,该mNativeWindow包含一些DEQUEUED Buffer,需确保所有Buffer是QUEUED或Canceld
E/BufferQueue( 2174): [SurfaceView] setBufferCount: client owns some buffers
E/Surface (17172): IGraphicBufferProducer::setBufferCount(10) returned Invalid argument

E/BufferQueue(2170): [SurfaceView] setBufferCount: client owns some buffers
E/Surface(3176): IGraphicBufferProducer::setBufferCount(10) returned Invalid argument

2、queueBuffer failure
queueBuffer调用失败,需确认该Buffer当前的状态,state=2 即QUEUED
E/BufferQueue( 2174): [SurfaceView] queueBuffer: slot 4 is not owned by the client (state=2)
E/Surface (17172): queueBuffer: error queuing buffer to SurfaceTexture, -22

queueBuffer调用失败,需确认该Buffer当前的状态,state=3 即ACQUIRED
E/BufferQueue(2190): [SurfaceView] queueBuffer: slot 0 is not owned by the client (state=3)
E/Surface(7246): queueBuffer: error queuing buffer to SurfaceTexture, -22

3、dequeueBuffer failure
native_window_dequeue_buffer_and_wait调用失败,需提前配置Surface,配置方式native_window_set_buffer_count
E/BufferQueue( 2444): [ScreenshotClient] dequeueBuffer: can't dequeue multiple buffers without setting the buffer count

4、cancelBuffer failure
02-01 08:11:52.635: E/Surface(3176): getSlotFromBufferLocked: unknown buffer: 0x63a4f9e0

相关概念
Producer 生产者 应用程序 客户端
Consumer 消费者 BufferQueue 服务端

BufferSlot::FREE 0 Buffer当前可用,也就是说可以被dequeued。此时Buffer的owner可认为是BufferQueue
BufferSlot::DEQUEUED 1 Buffer已经被dequeued,还未被queued或canceld。此时Buffer的owner可认为是producer(应用程序),这意味着server端(BufferQueue)不可以对这块缓冲区进行操作
BufferSlot::QUEUED 2 Buffer已经被客户端queued,除特别情况外此时还不能对它进行dequeue,而可以acquired。此时的owner是BufferQueue
BufferSlot::ACQUIRED 3 Buffer的owner改为consumer,可以released,然后状态又返回FREE
过程:FREE->DEQUEUED->QUEUED->ACQUIRED->FREE

frameworks\native\libs\FramebufferNativeWindow.cpp
typedef struct ANativeWindowBuffer{#ifdef __cplusplus    ANativeWindowBuffer() {        common.magic = ANDROID_NATIVE_BUFFER_MAGIC;        common.version = sizeof(ANativeWindowBuffer);        memset(common.reserved, 0, sizeof(common.reserved));    }    // Implement the methods that sp<ANativeWindowBuffer> expects so that it    // can be used to automatically refcount ANativeWindowBuffer's.    void incStrong(const void* id) const {        common.incRef(const_cast<android_native_base_t*>(&common));    }    void decStrong(const void* id) const {        common.decRef(const_cast<android_native_base_t*>(&common));    }#endif    struct android_native_base_t common;    int width;    int height;    int stride;    int format;    int usage;    void* reserved[2];    buffer_handle_t handle;    void* reserved_proc[8];} ANativeWindowBuffer_t;
  相关解决方案