hc
2023-05-26 a23f51ed7a39e452c1037343a84d7db1ca2c5bd7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
 *  Copyright (c) 2019 Rockchip Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
 
 
#include "FecParamStream.h"
#include "rkispp-config.h"
#include "CamHwIsp20.h"
namespace RkCam {
 
FecParamStream::FecParamStream (SmartPtr<V4l2Device> dev, int type)
    : RKStream(dev, type)
{
    _dev->open();
    mParamsAssembler = new IspParamsAssembler("FEC_PARAMS_ASSEMBLER");
}
 
FecParamStream::FecParamStream (const rk_sensor_full_info_t *s_info)
    : RKStream(s_info->ispp_info->pp_fec_params_path, ISPP_POLL_FEC_PARAMS)
{
    _dev->open();
    mParamsAssembler = new IspParamsAssembler("FEC_PARAMS_ASSEMBLER");
}
 
 
FecParamStream::~FecParamStream()
{
}
 
void
FecParamStream::start()
{
    XCamReturn ret = XCAM_RETURN_NO_ERROR;
 
    if (!_dev->is_activated()) {
        RKStream::start();
    }
    // set inital params
    ret = mParamsAssembler->start();
    if (ret < 0) {
        LOGE_CAMHW_SUBM(ISP20HW_SUBM, "params assembler start err: %d\n", ret);
        return;
    }
 
    if (mParamsAssembler->ready())
        configToDrv(0);
    else
        LOGE_CAMHW_SUBM(ISP20HW_SUBM, "no inital fec params ready");
}
 
void
FecParamStream::stop()
{
    RKStream::stop();
    if (mParamsAssembler.ptr())
        mParamsAssembler->stop();
}
 
void FecParamStream::set_devices(CamHwIsp20* camHw, SmartPtr<V4l2SubDevice> isppdev)
{
    mIsppSubDev = isppdev;
    mCamHw = camHw;
}
 
XCamReturn FecParamStream::configToDrv(uint32_t frameId)
{
    XCamReturn ret = XCAM_RETURN_NO_ERROR;
    XCAM_ASSERT (mParamsAssembler.ptr());
 
    SmartPtr<V4l2Buffer> v4l2buf_fec;
    struct rkispp_params_feccfg *ispp_fec_params = NULL;
 
    if (!mParamsAssembler->ready()) {
        LOGI_CAMHW_SUBM(ISP20HW_SUBM, "have no fec new parameter\n");
        return XCAM_RETURN_ERROR_PARAM;
    }
 
    ret = _dev->get_buffer(v4l2buf_fec);
    if (ret) {
        LOGW_CAMHW_SUBM(ISP20HW_SUBM, "Can not get ispp fec params buffer\n");
        return XCAM_RETURN_ERROR_PARAM;
    }
 
    cam3aResultList ready_results;
    ret = mParamsAssembler->deQueOne(ready_results, frameId);
    if (ret != XCAM_RETURN_NO_ERROR) {
        LOGI_CAMHW_SUBM(ISP20HW_SUBM, "deque parameter failed\n");
        ret = XCAM_RETURN_ERROR_PARAM;
        goto ret_fec_buf;
    }
 
    ispp_fec_params = (struct rkispp_params_feccfg*)v4l2buf_fec->get_buf().m.userptr;
    if (mCamHw->get_fec_cfg_params(ready_results, *ispp_fec_params) != XCAM_RETURN_NO_ERROR)
        LOGE_CAMHW_SUBM(ISP20HW_SUBM, "fec parameter translation error\n");
 
    LOGD_CAMHW_SUBM(ISP20HW_SUBM, "fec: en update 0x%x, ens 0x%x, cfg update 0x%x",
                    ispp_fec_params->head.module_en_update, ispp_fec_params->head.module_ens,
                    ispp_fec_params->head.module_cfg_update);
    if (memcmp(&last_ispp_fec_params, ispp_fec_params, sizeof(last_ispp_fec_params)) == 0) {
        LOGD_CAMHW_SUBM(ISP20HW_SUBM, "fec: no need update !");
        ret = XCAM_RETURN_NO_ERROR;
        goto ret_fec_buf;
    }
 
    last_ispp_fec_params = *ispp_fec_params;
    if ((ispp_fec_params->head.module_cfg_update) || (ispp_fec_params->head.module_en_update)) {
        ispp_fec_params->head.frame_id = frameId;
        //ispp_fec_params->image.index = ispp_params->fec_output_buf_index;
        //ispp_fec_params->image.size = ispp_params->fec_output_buf_size;
        //TODO set update bits
        if (_dev->queue_buffer (v4l2buf_fec) != 0) {
            LOGE_CAMHW_SUBM(ISP20HW_SUBM, "RKISP1: fec: failed to ioctl VIDIOC_QBUF for index %d, %d %s.\n",
                            v4l2buf_fec->get_buf().index, errno, strerror(errno));
            goto ret_fec_buf;
        }
    } else
        goto ret_fec_buf;
 
    return XCAM_RETURN_NO_ERROR;
 
ret_fec_buf:
    if (v4l2buf_fec.ptr())
        _dev->return_buffer_to_pool (v4l2buf_fec);
    return ret;
}
 
XCamReturn FecParamStream::config_params(uint32_t frameId, SmartPtr<cam3aResult>& result)
{
    XCamReturn ret = XCAM_RETURN_NO_ERROR;
    XCAM_ASSERT (mParamsAssembler.ptr());
 
    // params device should started befor any params queued
    if (!_dev->is_activated()) {
        mParamsAssembler->addReadyCondition(result->getType());
        mParamsAssembler->queue(result);
    } else {
        mParamsAssembler->queue(result);
        // set all ready params to drv
        while (mParamsAssembler->ready()) {
            if (configToDrv(frameId) != XCAM_RETURN_NO_ERROR)
                break;
        }
    }
 
    return ret;
}
}; //namspace RkCam