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