Example #1
0
XCamReturn
SmartAnalyzer::analyze (SmartPtr<BufferProxy> &buffer)
{
    XCamReturn ret = XCAM_RETURN_NO_ERROR;
    X3aResultList results;

    if (!buffer.ptr ()) {
        XCAM_LOG_DEBUG ("SmartAnalyzer::analyze got NULL buffer!");
        return XCAM_RETURN_ERROR_PARAM;
    }

    SmartHandlerList::iterator i_handler = _handlers.begin ();
    for (; i_handler != _handlers.end ();  ++i_handler)
    {
        SmartPtr<SmartAnalysisHandler> handler = *i_handler;
        if (!handler->is_valid ())
            continue;

        ret = handler->analyze (buffer, results);
        if (ret != XCAM_RETURN_NO_ERROR && ret != XCAM_RETURN_BYPASS) {
            XCAM_LOG_WARNING ("smart analyzer analyze handler(%s) context failed", XCAM_STR(handler->get_name()));
            handler->destroy_context ();
        }
    }

    if (!results.empty ()) {
        set_results_timestamp (results, buffer->get_timestamp ());
        notify_calculation_done (results);
    }

    return XCAM_RETURN_NO_ERROR;
}
Example #2
0
void
X3aAnalyzeTuner::x3a_calculation_done (XAnalyzer *analyzer, X3aResultList &results)
{
    XCAM_UNUSED (analyzer);
    _results.clear ();
    _results.assign (results.begin (), results.end ());
}
Example #3
0
void
XCamSmartAnalyerContext::x3a_calculation_done (XAnalyzer *analyzer, X3aResultList &results)
{
    XCAM_UNUSED (analyzer);
    SmartLock  locker (_result_mutex);
    _results.insert (_results.end (), results.begin (), results.end ());
}
Example #4
0
XCamReturn
X3aAnalyzer::analyze_3a_statistics (SmartPtr<X3aStats> &stats)
{
    XCamReturn ret = XCAM_RETURN_NO_ERROR;
    X3aResultList results;

    ret = pre_3a_analyze (stats);
    if (ret != XCAM_RETURN_NO_ERROR) {
        notify_calculation_failed(
            NULL, stats->get_timestamp (), "ae calculation failed");
        return ret;
    }

    ret = _ae_handler->analyze (results);
    if (ret != XCAM_RETURN_NO_ERROR) {
        notify_calculation_failed(
            _ae_handler.ptr(), stats->get_timestamp (), "ae calculation failed");
        return ret;
    }

    ret = _awb_handler->analyze (results);
    if (ret != XCAM_RETURN_NO_ERROR) {
        notify_calculation_failed(
            _awb_handler.ptr(), stats->get_timestamp (), "awb calculation failed");
        return ret;
    }

    ret = _af_handler->analyze (results);
    if (ret != XCAM_RETURN_NO_ERROR) {
        notify_calculation_failed(
            _af_handler.ptr(), stats->get_timestamp (), "af calculation failed");
        return ret;
    }

    ret = _common_handler->analyze (results);
    if (ret != XCAM_RETURN_NO_ERROR) {
        notify_calculation_failed(
            _common_handler.ptr(), stats->get_timestamp (), "3a other calculation failed");
        return ret;
    }

    ret = post_3a_analyze (results);
    if (ret != XCAM_RETURN_NO_ERROR) {
        notify_calculation_failed(
            NULL, stats->get_timestamp (), "3a collect results failed");
        return ret;
    }

    if (!results.empty ())
        notify_calculation_done (results);

    return ret;

}
Example #5
0
uint32_t
XCamSmartAnalyerContext::get_results (X3aResultList &results)
{
    uint32_t size = 0;
    SmartLock  locker (_result_mutex);

    results.assign (_results.begin (), _results.end ());
    size = _results.size ();
    _results.clear ();

    return size;
}
Example #6
0
void
x3a_list_remove_result (X3aResultList &list, uint32_t type)
{
    for (X3aResultList::iterator i = list.begin (); i != list.end ();) {
        SmartPtr<X3aResult> &result = *i;
        XCAM_ASSERT (result.ptr ());
        if (result->get_type () == type) {
            list.erase (i++);
            continue;
        }
        ++i;
    }
}
Example #7
0
XCamReturn
CL3aImageProcessor::apply_3a_results (X3aResultList &results)
{
    XCamReturn ret = XCAM_RETURN_NO_ERROR;

    for (X3aResultList::iterator iter = results.begin (); iter != results.end (); ++iter)
    {
        SmartPtr<X3aResult> &result = *iter;
        ret = apply_3a_result (result);
        if (ret != XCAM_RETURN_NO_ERROR)
            break;
    }
    return ret;
}
Example #8
0
void
AnalyzerCallback::x3a_calculation_done (X3aAnalyzer *analyzer, X3aResultList &results)
{
    XCAM_UNUSED (analyzer);

    for (X3aResultList::iterator i_res = results.begin();
            i_res != results.end(); ++i_res) {
        SmartPtr<X3aResult> res = *i_res;
        if (res.ptr() == NULL) continue;
        XCAM_LOG_DEBUG (
            "calculated 3a result(type:%d, timestamp:" XCAM_TIMESTAMP_FORMAT ")",
            res->get_type (), XCAM_TIMESTAMP_ARGS (res->get_timestamp ()));
    }
}
Example #9
0
void
X3aAnalyzer::notify_calculation_done (X3aResultList &results)
{
    XCAM_ASSERT (!results.empty ());
    if (_callback)
        _callback->x3a_calculation_done (this, results);
}
Example #10
0
XCamReturn AiqCompositor::integrate (X3aResultList &results)
{
    IspInputParameters isp_params;
    ia_aiq_pa_input_params pa_input;
    ia_aiq_pa_results *pa_result = NULL;
    ia_err ia_error = ia_err_none;
    ia_binary_data output;
    AiqAeHandler *aiq_ae = _ae_handler.ptr();
    AiqAwbHandler *aiq_awb = _awb_handler.ptr();
    AiqAfHandler *aiq_af = _af_handler.ptr();
    AiqCommonHandler *aiq_common = _common_handler.ptr();
    struct atomisp_parameters *isp_3a_result = NULL;
    SmartPtr<X3aResult> isp_results;

    XCAM_FAIL_RETURN (
        ERROR,
        aiq_ae && aiq_awb && aiq_af && aiq_common,
        XCAM_RETURN_ERROR_PARAM,
        "handlers are not AIQ inherited");

    xcam_mem_clear (&pa_input);
    pa_input.frame_use = _frame_use;
    pa_input.awb_results = aiq_awb->get_result ();
    if (aiq_ae->is_started())
        pa_input.exposure_params = (aiq_ae->get_result ())->exposures[0].exposure;
    pa_input.sensor_frame_params = &_frame_params;
    pa_input.color_gains = NULL;

    ia_error = ia_aiq_pa_run (_ia_handle, &pa_input, &pa_result);
    if (ia_error != ia_err_none) {
        XCAM_LOG_WARNING ("AIQ pa run failed"); // but not return error
    }
    _pa_result = pa_result;

    isp_params.frame_use = _frame_use;
    isp_params.awb_results = aiq_awb->get_result ();
    if (aiq_ae->is_started())
        isp_params.exposure_results = (aiq_ae->get_result ())->exposures[0].exposure;
    isp_params.gbce_results = aiq_common->get_gbce_result ();
    isp_params.sensor_frame_params = &_frame_params;
    isp_params.pa_results = pa_result;

    isp_params.manual_brightness = (int8_t)(aiq_common->get_brightness_unlock() * 128.0);
    isp_params.manual_contrast = (int8_t)(aiq_common->get_contrast_unlock() * 128.0);
    isp_params.manual_saturation = (int8_t)(aiq_common->get_saturation_unlock() * 128.0);
    isp_params.manual_hue = (int8_t)(aiq_common->get_hue_unlock() * 128.0);
    isp_params.manual_sharpness = (int8_t)(aiq_common->get_sharpness_unlock() * 128.0);
    isp_params.manual_nr_level = (int8_t)(aiq_common->get_nr_level_unlock() * 128.0);

    xcam_mem_clear (&output);
    if (!_adaptor->run (&isp_params, &output)) {
        XCAM_LOG_ERROR("Aiq to isp adaptor running failed");
        return XCAM_RETURN_ERROR_ISP;
    }
    isp_3a_result = ((struct atomisp_parameters *)output.data);
    isp_results = generate_3a_configs (isp_3a_result);
    results.push_back (isp_results);
    return XCAM_RETURN_NO_ERROR;
}
Example #11
0
void
SmartAnalyzer::post_smart_results (X3aResultList &results, int64_t timestamp)
{
    if (!results.empty ()) {
        set_results_timestamp (results, timestamp);
        notify_calculation_done (results);
    }
}
Example #12
0
XCamReturn
HybridAnalyzer::post_3a_analyze (X3aResultList &results)
{
    XCamReturn ret = XCAM_RETURN_NO_ERROR;
    SmartPtr<X3aStats> stats = get_cur_stats ();

    if ((ret = DynamicAnalyzer::post_3a_analyze (results)) != XCAM_RETURN_NO_ERROR) {
        return ret;
    }

    for (X3aResultList::iterator i_res = results.begin ();
            i_res != results.end (); ++i_res) {
        SmartPtr<X3aResult> result = *i_res;

        switch (result->get_type ()) {
        case XCAM_3A_RESULT_EXPOSURE: {
            XCam3aResultExposure *res = (XCam3aResultExposure *) result->get_ptr ();
            _analyzer_aiq->set_ae_mode (XCAM_AE_MODE_MANUAL);
            _analyzer_aiq->set_ae_manual_exposure_time (res->exposure_time);
            _analyzer_aiq->set_ae_manual_analog_gain (res->analog_gain);
            break;
        }
        case XCAM_3A_RESULT_WHITE_BALANCE: {
            _analyzer_aiq->set_awb_mode (XCAM_AWB_MODE_MANUAL);
            XCam3aResultWhiteBalance *res = (XCam3aResultWhiteBalance *) result->get_ptr ();
            _analyzer_aiq->set_awb_manual_gain (res->gr_gain, res->r_gain, res->b_gain, res->gb_gain);
            break;
        }
        default:
            break;
        }
    }
    results.clear ();

    SmartPtr<X3aIspStatistics> isp_stats = stats.dynamic_cast_ptr<X3aIspStatistics> ();
    if (!isp_stats.ptr ()) {
        if (!_stats_pool.ptr () && setup_stats_pool (stats->get_stats ()) != XCAM_RETURN_NO_ERROR)
            return XCAM_RETURN_ERROR_MEM;
        isp_stats = convert_to_isp_stats (stats);
    }
    return _analyzer_aiq->push_3a_stats (isp_stats);
}
Example #13
0
XCamReturn
X3aAnalyzeTuner::post_3a_analyze (X3aResultList &results)
{
    XCamReturn ret = XCAM_RETURN_NO_ERROR;

    XCAM_ASSERT (_analyzer.ptr ());
    ret = _analyzer->push_3a_stats (_stats);
    _stats.release ();

    results.insert (results.end (), _results.begin (), _results.end ());
    _results.clear ();

    X3aCiqTuningHandlerList::iterator i_handler = _handlers.begin ();
    for (; i_handler != _handlers.end ();  ++i_handler)
    {
        (*i_handler)->analyze (results);
    }

    return ret;
}
Example #14
0
XCamReturn
AiqAeHandler::analyze (X3aResultList &output)
{
    ia_aiq  *ia_handle = NULL;
    ia_aiq_ae_results *ae_result = NULL;
    ia_aiq_exposure_sensor_parameters *cur_sensor_result = NULL;
    ia_err ia_error = ia_err_none;
    bool need_apply = false;
    SmartPtr<X3aResult> result;

    AnalyzerHandler::HanlderLock lock(this);

    if (!ensure_ia_parameters ()) {
        XCAM_LOG_ERROR ("AIQ AE ensure ia parameters failed");
        return XCAM_RETURN_ERROR_PARAM;
    }

    ia_handle = _aiq_compositor->get_handle ();
    XCAM_ASSERT (ia_handle);
    ia_error = ia_aiq_ae_run (ia_handle, &_input, &ae_result);
    XCAM_FAIL_RETURN (ERROR, ia_error == ia_err_none, XCAM_RETURN_ERROR_AIQ, "AIQ run AE failed");

    cur_sensor_result = ae_result->exposures[0].sensor_exposure;

    if (!_started) {
        _result.copy (ae_result);
        _started = true;
        need_apply = true;
    } else {
        //TODO
        ia_aiq_exposure_sensor_parameters *last_sensor_res = &_result.sensor_exp_param;
        if (last_sensor_res->coarse_integration_time !=  cur_sensor_result->coarse_integration_time ||
                last_sensor_res->fine_integration_time !=  cur_sensor_result->fine_integration_time ||
                last_sensor_res->analog_gain_code_global !=  cur_sensor_result->analog_gain_code_global ||
                last_sensor_res->digital_gain_global !=  cur_sensor_result->digital_gain_global) {
            ia_aiq_exposure_sensor_parameters cur_cp_res = *cur_sensor_result;
            if (!manual_control_result (cur_cp_res, *last_sensor_res)) {
                XCAM_LOG_WARNING ("manual control AE result failed");
            }
            _result.copy (ae_result);
            _result.sensor_exp_param = cur_cp_res;
            need_apply = true;
        }
    }

    if (need_apply) {
        result = pop_result ();
        if (result.ptr())
            output.push_back (result);
    }

    return XCAM_RETURN_NO_ERROR;
}
Example #15
0
XCamReturn
SampleHandler::analyze (XCamVideoBuffer *buffer)
{
    XCAM_LOG_DEBUG ("Smart SampleHandler::analyze on ts:" XCAM_TIMESTAMP_FORMAT, XCAM_TIMESTAMP_ARGS (buffer->timestamp));
    if (NULL == buffer) {
        return XCAM_RETURN_ERROR_PARAM;
    }
    XCamReturn ret = XCAM_RETURN_NO_ERROR;

    XCAM_LOG_DEBUG ("format(0x%x), color_bits(%d)", buffer->info.format, buffer->info.color_bits);
    XCAM_LOG_DEBUG ("size(%d), components(%d)", buffer->info.size, buffer->info.components);
    XCAM_LOG_DEBUG ("width(%d), heitht(%d)", buffer->info.width, buffer->info.height);
    XCAM_LOG_DEBUG ("aligned_width(%d), aligned_height(%d)", buffer->info.aligned_width, buffer->info.aligned_height);

    _frameSaver->save_frame (buffer);

    X3aResultList results;
    XCam3aResultBrightness xcam3a_brightness_result;
    xcam_mem_clear (xcam3a_brightness_result);
    xcam3a_brightness_result.head.type =   XCAM_3A_RESULT_BRIGHTNESS;
    xcam3a_brightness_result.head.process_type = XCAM_IMAGE_PROCESS_ALWAYS;
    xcam3a_brightness_result.head.version = XCAM_VERSION;
    xcam3a_brightness_result.brightness_level = 9.9;

    SmartPtr<X3aResult> brightness_result =
        X3aResultFactory::instance ()->create_3a_result ((XCam3aResultHead*)&xcam3a_brightness_result);
    results.push_back(brightness_result);

    if (_callback) {
        if (XCAM_RETURN_NO_ERROR == ret) {
            _callback->x3a_calculation_done (NULL, results);
        } else {
            _callback->x3a_calculation_failed (NULL, buffer->timestamp, "pre 3a analyze failed");
        }
    }

    return ret;
}
Example #16
0
uint32_t
translate_3a_results_to_xcam (X3aResultList &list,
                              XCam3aResultHead *results[], uint32_t max_count)
{
    uint32_t result_count = 0;
    for (X3aResultList::iterator iter = list.begin (); iter != list.end (); ++iter) {
        SmartPtr<X3aResult> &isp_result = *iter;

        switch (isp_result->get_type()) {
        case X3aIspConfig::IspExposureParameters: {
            SmartPtr<X3aIspExposureResult> isp_exposure =
                isp_result.dynamic_cast_ptr<X3aIspExposureResult> ();
            XCAM_ASSERT (isp_exposure.ptr ());
            const XCam3aResultExposure &exposure = isp_exposure->get_standard_result ();
            XCam3aResultExposure *new_exposure = xcam_malloc0_type (XCam3aResultExposure);
            *new_exposure = exposure;
            new_exposure->head.type = XCAM_3A_RESULT_EXPOSURE;
            new_exposure->head.process_type = XCAM_IMAGE_PROCESS_ALWAYS;
            new_exposure->head.version = XCAM_VERSION;
            results[result_count++] = (XCam3aResultHead*)new_exposure;
            break;
        }
        case X3aIspConfig::IspAllParameters: {
            SmartPtr<X3aAtomIspParametersResult> isp_3a_all =
                isp_result.dynamic_cast_ptr<X3aAtomIspParametersResult> ();
            XCAM_ASSERT (isp_3a_all.ptr ());
            const struct atomisp_parameters &atomisp_params = isp_3a_all->get_isp_config ();
            result_count += translate_atomisp_parameters (atomisp_params, &results[result_count], max_count - result_count);
            break;
        }
        default:
            XCAM_LOG_WARNING ("unknow type(%d) in translation", isp_result->get_type());
            break;
        }
    }
    return result_count;
}
Example #17
0
void
XCam3AAiqContext::update_brightness_result(XCamCommonParam *params)
{
    if( params->brightness == _brightness_level)
        return;
    _brightness_level = params->brightness;

    XCam3aResultBrightness *xcam3a_brightness_result = xcam_malloc0_type (XCam3aResultBrightness);
    xcam3a_brightness_result->head.type =   XCAM_3A_RESULT_BRIGHTNESS;
    xcam3a_brightness_result->head.process_type = XCAM_IMAGE_PROCESS_ALWAYS;
    xcam3a_brightness_result->head.version = XCAM_VERSION;
    xcam3a_brightness_result->brightness_level = _brightness_level;

    SmartPtr<X3aResult> brightness_result =
        X3aResultFactory::instance ()->create_3a_result ((XCam3aResultHead*)xcam3a_brightness_result);
    _results.push_back(brightness_result);
}
Example #18
0
void
HybridAnalyzer::x3a_calculation_done (XAnalyzer *analyzer, X3aResultList &results)
{
    XCAM_UNUSED (analyzer);

    static XCam3aResultHead *res_heads[XCAM_3A_MAX_RESULT_COUNT];
    xcam_mem_clear (res_heads);
    XCAM_ASSERT (results.size () < XCAM_3A_MAX_RESULT_COUNT);

    uint32_t result_count = translate_3a_results_to_xcam (results,
                            res_heads, XCAM_3A_MAX_RESULT_COUNT);
    convert_results (res_heads, result_count, results);
    for (uint32_t i = 0; i < result_count; ++i) {
        if (res_heads[i])
            free_3a_result (res_heads[i]);
    }

    notify_calculation_done (results);
}
XCamReturn
X3aCiqTnrTuningHandler::analyze (X3aResultList &output)
{
    XCamReturn ret = XCAM_RETURN_NO_ERROR;

    const X3aCiqTnrTuningStaticData* tuning = imx185_tuning;
    if (NULL != _tuning_data) {
        tuning = (X3aCiqTnrTuningStaticData*)_tuning_data;;
    }

    XCam3aResultTemporalNoiseReduction config;
    SmartPtr<X3aTemporalNoiseReduction> rgb_result = new X3aTemporalNoiseReduction (XCAM_3A_RESULT_TEMPORAL_NOISE_REDUCTION_RGB);
    SmartPtr<X3aTemporalNoiseReduction> yuv_result = new X3aTemporalNoiseReduction (XCAM_3A_RESULT_TEMPORAL_NOISE_REDUCTION_YUV);

    double analog_gain = get_current_analog_gain ();
    double max_analog_gain = get_max_analog_gain ();
    XCAM_LOG_DEBUG ("get current AG = (%f), max AG = (%f)", analog_gain, max_analog_gain);

    uint8_t i_curr = 0;
    uint8_t i_prev = 0;
    for (i_curr = 0; i_curr < X3A_CIQ_GAIN_STEPS; i_curr++) {
        if (analog_gain <= tuning[i_curr].analog_gain) {
            break;
        }
        i_prev = i_curr;
    }
    if (i_curr >= X3A_CIQ_GAIN_STEPS) {
        i_curr = X3A_CIQ_GAIN_STEPS - 1;
    }

    //Calculate YUV config
    xcam_mem_clear (config);
    config.gain = linear_interpolate_p2 (tuning[i_prev].yuv_gain, tuning[i_curr].yuv_gain,
                                         tuning[i_prev].analog_gain, tuning[i_curr].analog_gain, analog_gain);

    config.threshold[0] = linear_interpolate_p2 (tuning[i_prev].y_threshold, tuning[i_curr].y_threshold,
                          tuning[i_prev].analog_gain, tuning[i_curr].analog_gain, analog_gain);

    config.threshold[1] = linear_interpolate_p2 (tuning[i_prev].uv_threshold, tuning[i_curr].uv_threshold,
                          tuning[i_prev].analog_gain, tuning[i_curr].analog_gain, analog_gain);

    config.threshold[2] = 0.0;
    XCAM_LOG_DEBUG ("Calculate YUV temporal noise reduction config: yuv_gain(%f), y_threshold(%f), uv_threshold(%f)",
                    config.gain, config.threshold[0], config.threshold[1]);

    yuv_result->set_standard_result (config);
    output.push_back (yuv_result);

    //Calculate RGB config
    xcam_mem_clear (config);
    config.gain = linear_interpolate_p2 (tuning[i_prev].rgb_gain, tuning[i_curr].rgb_gain,
                                         tuning[i_prev].analog_gain, tuning[i_curr].analog_gain, analog_gain);

    config.threshold[0] = linear_interpolate_p2 (tuning[i_prev].r_threshold, tuning[i_curr].r_threshold,
                          tuning[i_prev].analog_gain, tuning[i_curr].analog_gain, analog_gain);

    config.threshold[1] = linear_interpolate_p2 (tuning[i_prev].g_threshold, tuning[i_curr].g_threshold,
                          tuning[i_prev].analog_gain, tuning[i_curr].analog_gain, analog_gain);

    config.threshold[2] = linear_interpolate_p2 (tuning[i_prev].b_threshold, tuning[i_curr].b_threshold,
                          tuning[i_prev].analog_gain, tuning[i_curr].analog_gain, analog_gain);

    XCAM_LOG_DEBUG ("Calculate RGB temporal noise reduction config: rgb_gain(%f), r_threshold(%f), g_threshold(%f), b_threshold(%f)",
                    config.gain, config.threshold[0], config.threshold[1], config.threshold[2]);

    rgb_result->set_standard_result (config);
    output.push_back (rgb_result);

    return ret;
}