/* * 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 "TnrStatsStream.h" #include "SPStreamProcUnit.h" #include "rkispp-config.h" #include "CamHwIsp20.h" namespace RkCam { TnrStatsStream::TnrStatsStream (SmartPtr dev, int type) : RKStream(dev, type) , _fd_init_flag(true) { setPollCallback (this); } TnrStatsStream::~TnrStatsStream() { } void TnrStatsStream::start() { RKStream::start(); } void TnrStatsStream::stop() { RKStream::stopThreadOnly(); deinit_tnrbuf(); RKStream::stopDeviceOnly(); } void TnrStatsStream::set_device(CamHwIsp20* camHw, SmartPtr dev) { _ispp_dev = dev; _camHw = camHw; } SmartPtr TnrStatsStream::new_video_buffer(SmartPtr buf, SmartPtr dev) { if (_fd_init_flag) { init_tnrbuf(); _fd_init_flag = false; } struct rkispp_stats_tnrbuf *stats; //gainkg SmartPtr gainkg = new SubV4l2BufferProxy(buf, dev); stats = (struct rkispp_stats_tnrbuf *)(gainkg->get_v4l2_userptr()); LOGD("%s:kg_indx=%d,g_indx=%d,frame_id=%d\n",__FUNCTION__, stats->gainkg.index, stats->gain.index, stats->frame_id); gainkg->set_buff_info(get_fd_by_index(stats->gainkg.index), stats->gainkg.size); gainkg->_buf_type = ISPP_GAIN_KG; return gainkg; } XCamReturn TnrStatsStream::poll_buffer_ready (SmartPtr &buf) { if (_camHw->mHwResLintener) { struct rkispp_stats_tnrbuf *stats; SmartPtr gainkg = buf.dynamic_cast_ptr(); stats = (struct rkispp_stats_tnrbuf *)(gainkg->get_v4l2_userptr()); //gainwr SmartPtr v4l2buf = gainkg.dynamic_cast_ptr(); SmartPtr gainwr = new SubVideoBuffer(v4l2buf); gainwr->_buf_type = ISPP_GAIN_WR; gainwr->set_buff_info(get_fd_by_index(stats->gain.index), stats->gain.size); gainwr->set_sequence(stats->frame_id); SmartPtr vbuf = gainwr.dynamic_cast_ptr(); _camHw->mHwResLintener->hwResCb(vbuf); //send gainwr _camHw->mHwResLintener->hwResCb(buf); //send gainkg } return XCAM_RETURN_NO_ERROR; } int TnrStatsStream::get_fd_by_index(uint32_t index) { #if 0 if (index < 0) return -1; for (int i=0; i<_buf_num; i++) { if (index == (int)_idx_array[i]) { return _fd_array[i]; } } return -1; #else int fd = -1; std::map::iterator it; it = _idx_fd_map.find(index); if (it == _idx_fd_map.end()) fd = -1; else fd = it->second; return fd; #endif } bool TnrStatsStream::init_tnrbuf() { struct rkispp_buf_idxfd isppbuf_fd; int res = -1; memset(&isppbuf_fd, 0, sizeof(isppbuf_fd)); res = _ispp_dev->io_control(RKISPP_CMD_GET_TNRBUF_FD , &isppbuf_fd); if (res) return false; LOGD("tnr buf_num=%d",isppbuf_fd.buf_num); for (uint32_t i=0; i::iterator it; for (it=_idx_fd_map.begin(); it!=_idx_fd_map.end(); ++it) ::close(it->second); _idx_fd_map.clear(); LOGD("%s exit", __FUNCTION__); } //void TnrStatsStream::connect_nr_stream(SmartPtr stream) //{ // _nr_stream_unit = stream; //} }; //namspace RkCam