第28讲 Buffer Limit Latency - Android Camera性能分析

2024年10月30日 第28讲 Buffer Limit Latency 极客笔记

本讲是Android Camera性能分析专题的第28讲,我们介绍CameraServer Buffer Limit Latency,包括如下内容:

  1. Buffer Limit Latency是什么
  2. Buffer Limit Latency配置
  3. Buffer Limit Latency实战
资源 描述
在线课程 极客笔记在线课程
知识星球 星球名称:深入浅出Android Camera
星球ID: 17296815
Wechat 极客笔记圈

Buffer Limit Latency是什么

Buffer Limit Latency用于衡量当某路Stream dequeue buffer数量达到producer的最大值后,等待HAL处理的耗时。

什么是numOutstandingBuffers

  • 已经送给HAL,HAL正在处理,未返回的Buffer数量
  • 视频讲解演示如何查看每路stream的numOutstandingBuffers

什么是camera_stream::max_buffers

  • Camera HAL配置的,在未返回buffer的情况下,最多dequeueBuffer的数量
  • 视频讲解演示如何查看每路stream HAL配置的最大max_buffers

Buffer Limit Latency配置

Buffer Limit Latency直方图配置

  • 分成10份(默认值), 间隔为33ms

    • static const int32_t kBufferLimitLatencyBinSize = 33; //in ms
    • Latency histogram of the wait time for handout buffer count to drop below max_buffers.

添加Sample的时机

  • 当numOutstandingBuffers等于camera_stream::max_buffers时,会等待新的Buffer返回,该Latency衡量的是这个等待时间

Buffer Limit Latency实战

// Wait for new buffer returned back if we are running into the limit.
size_t numOutstandingBuffers = getHandoutOutputBufferCountLocked();
if (numOutstandingBuffers == camera_stream::max_buffers) {
    ALOGV("%s: Already dequeued max output buffers (%d), wait for next returned one.",
                    __FUNCTION__, camera_stream::max_buffers);
    nsecs_t waitStart = systemTime(SYSTEM_TIME_MONOTONIC);
    if (waitBufferTimeout < kWaitForBufferDuration) {
        waitBufferTimeout = kWaitForBufferDuration;
    }
    res = mOutputBufferReturnedSignal.waitRelative(mLock, waitBufferTimeout);
    nsecs_t waitEnd = systemTime(SYSTEM_TIME_MONOTONIC);
    mBufferLimitLatency.add(waitStart, waitEnd);
    if (res != OK) {
        if (res == TIMED_OUT) {
            ALOGE("%s: wait for output buffer return timed out after %lldms (max_buffers %d)",
                    __FUNCTION__, waitBufferTimeout / 1000000LL,
                    camera_stream::max_buffers);
        }
        return res;
    }

    size_t updatedNumOutstandingBuffers = getHandoutOutputBufferCountLocked();
    if (updatedNumOutstandingBuffers >= numOutstandingBuffers) {
        ALOGE("%s: outsanding buffer count goes from %zu to %zu, "
                "getBuffer(s) call must not run in parallel!", __FUNCTION__,
                numOutstandingBuffers, updatedNumOutstandingBuffers);
        return INVALID_OPERATION;
    }
}

本文链接:http://so.lmcjl.com/news/16561/

展开阅读全文