/* * Copyright (C) 2017 Intel Corporation. * Copyright (c) 2017, Fuzhou Rockchip Electronics Co., Ltd * * 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 PSL_RKISP2_ImguUnit_H_ #define PSL_RKISP2_ImguUnit_H_ #include #include "RKISP2GraphConfigManager.h" #include "CaptureUnit.h" #include "MessageThread.h" #include "RKISP1CameraHw.h" #include "RKISP2CameraHw.h" #include "tasks/RKISP2ITaskEventSource.h" #include "tasks/RKISP2ICaptureEventSource.h" #include "tasks/RKISP2ExecuteTaskBase.h" #include "workers/RKISP2IDeviceWorker.h" #include "workers/RKISP2FrameWorker.h" #include "RKISP2MediaCtlHelper.h" #include "RKISP2CtrlLoop.h" namespace android { namespace camera2 { namespace rkisp2 { class RKISP2OutputFrameWorker; class RKISP2ImguUnit: public IMessageHandler, public IPollEventListener { public: RKISP2ImguUnit(int cameraId, RKISP2GraphConfigManager &gcm, std::shared_ptr sensorMediaCtl, std::shared_ptr imgMediaCtl); virtual ~RKISP2ImguUnit(); status_t flush(void); status_t configStreams(std::vector &activeStreams, bool configChanged, bool isStillStream); status_t configStreamsDone(); void cleanListener(); status_t completeRequest(std::shared_ptr &processingSettings, bool updateMeta); status_t attachListener(ICaptureEventListener *aListener); // IPollEvenListener virtual status_t notifyPollEvent(PollEventMessage *msg); virtual void registerErrorCallback(IErrorCallback* errCb) { mErrCb = errCb; } void getConfigedHwPathSize(const char* pathName, uint32_t &size); void getConfigedSensorOutputSize(uint32_t &size); void setCtrlLoop(RKISP2CtrlLoop* ctrlLoop){ this->mCtrlLoop = ctrlLoop; } private: status_t configureVideoNodes(std::shared_ptr graphConfig); status_t handleMessageCompleteReq(DeviceMessage &msg); status_t processNextRequest(); status_t handleMessagePoll(DeviceMessage msg); status_t handleMessageFlush(void); status_t updateProcUnitResults(Camera3Request &request, std::shared_ptr settings); status_t startProcessing(DeviceMessage msg); void updateMiscMetadata(CameraMetadata &result, std::shared_ptr settings) const; void updateDVSMetadata(CameraMetadata &result, std::shared_ptr settings) const; virtual void messageThreadLoop(void); status_t handleMessageExit(void); status_t requestExitAndWait(); status_t mapStreamWithDeviceNode(int phyStreamsNum); status_t createProcessingTasks(std::shared_ptr graphConfig); void setStreamListeners(NodeTypes nodeName, std::shared_ptr& source); status_t kickstart(int skipFrames); status_t stopAllWorkers(); void clearWorkers(); status_t skipBadFrames(); status_t allocatePublicStatBuffers(int numBufs); void freePublicStatBuffers(); private: enum ImguState { IMGU_RUNNING, IMGU_IDLE, }; enum ImguPipeType { PIPE_VIDEO_INDEX = 0, PIPE_STILL_INDEX, PIPE_NUM }; struct PipeConfiguration { std::vector> deviceWorkers; std::vector> pollableWorkers; std::vector> nodes; /* PollerThread owns this */ }; private: std::shared_ptr mMainOutWorker; std::shared_ptr mSelfOutWorker; std::shared_ptr mRawOutWorker; ImguState mState; bool mConfigChanged; bool mIsStillChangeStream; int mCameraId; RKISP2GraphConfigManager &mGCM; bool mThreadRunning; std::unique_ptr mMessageThread; MessageQueue mMessageQueue; StreamConfig mActiveStreams; std::vector> mListeningTasks; // Tasks that listen for events from another task. PipeConfiguration mPipeConfigs[PIPE_NUM]; std::vector> mFirstWorkers; std::vector mListenerDeviceWorkers; /* mListenerDeviceWorkers doesn't own RKISP2ICaptureEventSource objects */ std::vector mListeners; /* mListeners doesn't own ICaptureEventListener objects */ PipeConfiguration* mCurPipeConfig; RKISP2MediaCtlHelper mRKISP2MediaCtlHelper; std::unique_ptr mPollerThread; std::mutex mFlushMutex; /* proctec mFlushing */ bool mFlushing; /* avoid dead lock between poller thread and imgu message thread for sync flush */ std::vector> mMessagesPending; // Keep copy of message until workers start to handle it std::vector> mMessagesUnderwork; // Keep copy of message until workers have processed it std::vector mDelayProcessRequest; // Keep copy of message until workers have processed it std::map> mConfiguredNodesPerName; bool mFirstRequest; bool mNeedRestartPoll; //only for starting stats poll request in right time IErrorCallback * mErrCb; std::map mStreamNodeMapping; /* mStreamNodeMapping doesn't own camera3_stream_t objects */ std::map mStreamListenerMapping; std::map>> mRequestToWorkMap; static const int PUBLIC_STATS_POOL_SIZE = 9; static const int RKISP1_MAX_STATISTICS_WIDTH = 80; static const int RKISP1_MAX_STATISTICS_HEIGHT = 60; bool mTakingPicture; bool mIsFrameSkiped; bool mIsIncreaseTimeout = false; RKISP2CtrlLoop *mCtrlLoop; }; } /* namespace rkisp2 */ } /* namespace camera2 */ } /* namespace android */ #endif /* PSL_RKISP2_ImguUnit_H_ */