예제 #1
0
static XCamReturn
read_buf (SmartPtr<DrmBoBuffer> &buf, TestFileHandle &file)
{
    const VideoBufferInfo info = buf->get_video_info ();
    VideoBufferPlanarInfo planar;
    uint8_t *memory = NULL;
    XCamReturn ret = XCAM_RETURN_NO_ERROR;

    memory = buf->map ();
    for (uint32_t index = 0; index < info.components; index++) {
        info.get_planar_info (planar, index);
        uint32_t line_bytes = planar.width * planar.pixel_bytes;

        for (uint32_t i = 0; i < planar.height; i++) {
            if (fread (memory + info.offsets [index] + i * info.strides [index], 1, line_bytes, file.fp) != line_bytes) {
                if (feof (file.fp))
                    ret = XCAM_RETURN_BYPASS;
                else {
                    XCAM_LOG_ERROR ("read file failed, size doesn't match");
                    ret = XCAM_RETURN_ERROR_FILE;
                }
            }
        }
    }
    buf->unmap ();
    return ret;
}
예제 #2
0
XCamReturn
FakePollThread::read_buf (SmartPtr<DrmBoBuffer> &buf)
{
    uint8_t *dst = buf->map ();
    const VideoBufferInfo info = buf->get_video_info ();
    VideoBufferPlanarInfo planar;
    XCamReturn ret = XCAM_RETURN_NO_ERROR;

    for (uint32_t index = 0; index < info.components; index++) {
        info.get_planar_info(planar, index);
        uint32_t line_bytes = planar.width * planar.pixel_bytes;

        for (uint32_t i = 0; i < planar.height; i++) {
            if (fread (dst + info.offsets [index] + i * info.strides [index], 1, line_bytes, _raw) < line_bytes) {
                if (feof (_raw)) {
                    fseek (_raw, 0, SEEK_SET);
                    ret = XCAM_RETURN_BYPASS;
                } else {
                    XCAM_LOG_ERROR ("poll_buffer_loop failed to read file");
                    ret = XCAM_RETURN_ERROR_FILE;
                }
                goto done;
            }
        }
    }

done:
    buf->unmap ();
    return ret;
}
예제 #3
0
static XCamReturn
calculate_psnr (SmartPtr<DrmBoBuffer> &psnr_cur, SmartPtr<DrmBoBuffer> &psnr_ref, PsnrType psnr_type, float &psnr)
{
    const VideoBufferInfo info = psnr_cur->get_video_info ();
    VideoBufferPlanarInfo planar;
    uint8_t *cur_mem = NULL, *ref_mem = NULL;
    XCamReturn ret = XCAM_RETURN_NO_ERROR;

    int8_t interval = 1, index = 0;
    if (PSNRY == psnr_type) {
        interval = 1;
        index = 0;
    } else if (PSNRR == psnr_type) {
        interval = 4;
        index = 0;
    } else if (PSNRG == psnr_type) {
        interval = 4;
        index = 1;
    } else if (PSNRB == psnr_type) {
        interval = 4;
        index = 2;
    }

    cur_mem = psnr_cur->map ();
    ref_mem = psnr_ref->map ();
    if (!cur_mem || !ref_mem) {
        XCAM_LOG_ERROR ("calculate_psnr map buffer failed");
        return XCAM_RETURN_ERROR_MEM;
    }

    uint32_t sum = 0, pos = 0;
    info.get_planar_info (planar, 0);
    for (uint32_t i = 0; i < planar.height; i++) {
        for (uint32_t j = 0; j < planar.width / interval; j++) {
            pos = i * planar.width + j * interval + index;
            sum += (cur_mem [pos] - ref_mem [pos]) * (cur_mem [pos] - ref_mem [pos]);
        }
    }
    float mse = (float) sum / (planar.height * planar.width / interval) + 0.000001f;
    psnr = 10 * log10 (255 * 255 / mse);

    psnr_cur->unmap ();
    psnr_ref->unmap ();

    return ret;
}
예제 #4
0
XCamReturn
FakePollThread::init_buffer_pool ()
{
    struct v4l2_format format;
    if (!_capture_dev.ptr () ||
            _capture_dev->get_format (format) != XCAM_RETURN_NO_ERROR) {
        XCAM_LOG_ERROR ("Can't init buffer pool without format");
        return XCAM_RETURN_ERROR_PARAM;
    }
    VideoBufferInfo info;
    info.init(format.fmt.pix.pixelformat,
              format.fmt.pix.width,
              format.fmt.pix.height, 0, 0, 0);
#if HAVE_LIBDRM
    SmartPtr<DrmDisplay> drm_disp = DrmDisplay::instance ();
    _buf_pool = new DrmBoBufferPool (drm_disp);
    XCAM_ASSERT (_buf_pool.ptr ());

    if (_buf_pool->set_video_info (info) && _buf_pool->reserve (DEFAULT_FPT_BUF_COUNT))
        return XCAM_RETURN_NO_ERROR;
#endif

    return XCAM_RETURN_ERROR_MEM;
}
예제 #5
0
XCamReturn
SVStream::create_buf_pool (uint32_t reserve_count)
{
    XCAM_ASSERT (get_width () && get_height ());
    XCAM_FAIL_RETURN (
        ERROR, _module != SVModuleNone, XCAM_RETURN_ERROR_PARAM,
        "invalid module, please set module first");

    VideoBufferInfo info;
    info.init (V4L2_PIX_FMT_NV12, get_width (), get_height ());

    SmartPtr<BufferPool> pool;
    if (_module == SVModuleSoft) {
        pool = new SoftVideoBufAllocator (info);
    } else if (_module == SVModuleGLES) {
#if HAVE_GLES
        pool = new GLVideoBufferPool (info);
#endif
    } else if (_module == SVModuleVulkan) {
#if HAVE_VULKAN
        XCAM_ASSERT (_vk_dev.ptr ());
        pool = create_vk_buffer_pool (_vk_dev);
        XCAM_ASSERT (pool.ptr ());
        pool->set_video_info (info);
#endif
    }
    XCAM_ASSERT (pool.ptr ());

    if (!pool->reserve (reserve_count)) {
        XCAM_LOG_ERROR ("create buffer pool failed");
        return XCAM_RETURN_ERROR_MEM;
    }

    set_buf_pool (pool);
    return XCAM_RETURN_NO_ERROR;
}
예제 #6
0
bool
XCam3AAiqContext::setup_stats_pool (uint32_t bit_depth)
{
    VideoBufferInfo info;
    info.init (XCAM_PIX_FMT_SGRBG16, _video_width, _video_height);

    _stats_pool = new X3aStatisticsQueue;
    XCAM_ASSERT (_stats_pool.ptr ());

    _stats_pool->set_bit_depth (bit_depth);
    XCAM_FAIL_RETURN (
        WARNING,
        _stats_pool->set_video_info (info),
        false,
        "3a stats set video info failed");


    if (!_stats_pool->reserve (6)) {
        XCAM_LOG_WARNING ("init_3a_stats_pool failed to reserve stats buffer.");
        return false;
    }

    return true;
}
예제 #7
0
XCamReturn
CLBayer2RGBImageHandler::prepare_buffer_pool_video_info (
    const VideoBufferInfo &input,
    VideoBufferInfo &output)
{
    bool format_inited = output.init (_output_format, input.width, input.height);

    XCAM_FAIL_RETURN (
        WARNING,
        format_inited,
        XCAM_RETURN_ERROR_PARAM,
        "CL image handler(%s) ouput format(%s) unsupported",
        get_name (), xcam_fourcc_to_string (_output_format));

    return XCAM_RETURN_NO_ERROR;
}
XCamReturn
CLBayerBasicImageHandler::prepare_buffer_pool_video_info (
    const VideoBufferInfo &input,
    VideoBufferInfo &output)
{
    uint32_t format = XCAM_PIX_FMT_SGRBG16_planar;
    bool format_inited = output.init (format, input.width / 2 , input.height / 2);

    XCAM_FAIL_RETURN (
        WARNING,
        format_inited,
        XCAM_RETURN_ERROR_PARAM,
        "CL image handler(%s) output format(%s) unsupported",
        get_name (), xcam_fourcc_to_string (format));

    return XCAM_RETURN_NO_ERROR;
}