/* * RkAiqSharedDataWrapper.h * * 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. * */ #ifndef _RK_AIQ_SHARED_DATA_MANAGER_H_ #define _RK_AIQ_SHARED_DATA_MANAGER_H_ #include #include #include #include "rk_aiq_algo_types_int.h" #include "rk_aiq_pool.h" #include "thumbnails.h" namespace RkCam { typedef SharedItemBase sharedData; typedef std::list> sharedDataList; typedef std::map sharedDataMap; typedef struct RkAiqSofInfoWrapper_s : public SharedItemData { uint32_t sequence; SmartPtr preExp; SmartPtr curExp; int64_t sof; } RkAiqSofInfoWrapper_t; typedef SharedItemPool RkAiqIspStatsIntPool; typedef SharedItemProxy RkAiqIspStatsIntProxy; typedef SharedItemPool RkAiqAecStatsPool; typedef SharedItemProxy RkAiqAecStatsProxy; typedef SharedItemPool RkAiqAwbStatsPool; typedef SharedItemProxy RkAiqAwbStatsProxy; typedef SharedItemPool RkAiqAtmoStatsPool; typedef SharedItemProxy RkAiqAtmoStatsProxy; typedef SharedItemPool RkAiqAdehazeStatsPool; typedef SharedItemProxy RkAiqAdehazeStatsProxy; typedef SharedItemPool RkAiqAfStatsPool; typedef SharedItemProxy RkAiqAfStatsProxy; typedef SharedItemPool RkAiqSofInfoWrapperPool; typedef SharedItemProxy RkAiqSofInfoWrapperProxy; typedef SharedItemPool RkAiqOrbStatsPool; typedef SharedItemProxy RkAiqOrbStatsProxy; typedef struct RkAiqThumbnailSrcWrapper_s : public SharedItemData { SmartPtr thumbnail; } RkAiqThumbnailSrcWrapper_t; typedef SharedItemPool RkAiqThumbnailSrcPool; typedef SharedItemProxy RkAiqThumbnailSrcProxy; typedef SharedItemPool RkAiqAeProcResultPool; typedef SharedItemProxy RkAiqAeProcResultProxy; class RkAiqSharedDataManager { public: RkAiqSharedDataManager() { rwlock = PTHREAD_RWLOCK_INITIALIZER; if (pthread_rwlock_init(&rwlock, nullptr)) LOGE_ANALYZER("rwlock init failed!"); }; ~RkAiqSharedDataManager() { if (pthread_rwlock_destroy(&rwlock)) LOGE_ANALYZER("rwlock destory failed!"); }; bool push (const SmartPtr &data) { pthread_rwlock_wrlock(&rwlock); sharedDataList &list = mSharedDataMap[data->getId()]; list.push_back(data); pthread_rwlock_unlock(&rwlock); LOGD_ANALYZER("%s, sharedDatamap size %d, id(%d) push type: %d, list size: %d", __FUNCTION__, mSharedDataMap.size(), data->getId(), data->getType(), list.size()); return true; }; bool pop() { pthread_rwlock_wrlock(&rwlock); if (!mSharedDataMap.empty()) { auto list = mSharedDataMap.begin()->second; LOGD_ANALYZER("%s, sharedDatamap size %d, pop id(%d), list size: %d", __FUNCTION__, mSharedDataMap.size(), mSharedDataMap.begin()->first, list.size()); list.clear(); mSharedDataMap.erase(mSharedDataMap.begin()); } pthread_rwlock_unlock(&rwlock); return true; }; bool find (int32_t id, RkAiqSharedDataType type, SmartPtr &data) { pthread_rwlock_rdlock(&rwlock); auto mapIt = mSharedDataMap.find(id); if (mapIt == mSharedDataMap.end()) { LOGE_ANALYZER("can't find id(%d) in mSharedDataMap"); pthread_rwlock_unlock(&rwlock); return false; } auto list = mapIt->second; auto listIt = list.begin(); for (; listIt != list.end(); ++listIt) { if (type == listIt->ptr()->getType()) { data = *listIt; break; } } if (listIt == list.end()) { LOGE_ANALYZER("can't find type(%d) data in list", type); pthread_rwlock_unlock(&rwlock); return false; } pthread_rwlock_unlock(&rwlock); return true; }; uint32_t clear () { pthread_rwlock_wrlock(&rwlock); for (auto mapIt = mSharedDataMap.begin(); mapIt != mSharedDataMap.end();) { auto list = mapIt->second; list.clear(); mSharedDataMap.erase(mapIt++); } pthread_rwlock_unlock(&rwlock); return true; }; uint32_t get_size () { return mSharedDataMap.size(); }; bool get_exposure_params(int32_t id, RKAiqAecExpInfo_t **exp_param); bool get_ae_stats(int32_t id, rk_aiq_isp_aec_stats_t *aec_stats); bool get_awb_stats(int32_t id, rk_aiq_awb_stat_res_v200_t *awb_stats); bool get_af_stats(int32_t id, rk_aiq_isp_af_stats_t *af_stats); protected: private: sharedDataMap mSharedDataMap; pthread_rwlock_t rwlock; }; template struct AlgoRstShared: VideoBuffer { T result; virtual uint8_t *map (); virtual bool unmap (); virtual int get_fd (); }; template uint8_t *AlgoRstShared::map() { return (uint8_t *)(&result); } template bool AlgoRstShared::unmap() { return true; } template int AlgoRstShared::get_fd () { return -1; } using RkAiqAlgoPreResAeIntShared = AlgoRstShared; using RkAiqAlgoProcResAeIntShared = AlgoRstShared; using RkAiqAlgoProcResAwbIntShared = AlgoRstShared; using RkAiqAlgoProcResAfIntShared = AlgoRstShared; using RkAiqAlgoProcResAmdIntShared = AlgoRstShared; }; #endif // _RK_AIQ_SHARED_DATA_MANAGER_H_