1 /* 2 * Copyright 2020 Rockchip Electronics Co. LTD 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 #ifndef SRC_RT_TASK_TASK_GRAPH_RTTASKNODECONTEXT_H_ 19 #define SRC_RT_TASK_TASK_GRAPH_RTTASKNODECONTEXT_H_ 20 21 #include <string> 22 #include <vector> 23 #include <list> 24 #include <memory> 25 #include <map> 26 27 #include "rt_header.h" 28 #include "rt_metadata.h" 29 #include "RTStreamInfo.h" 30 31 class RTMediaBuffer; 32 class RTBufferListener; 33 class RTOutputStreamShared; 34 class RTMediaBufferPool; 35 class RTTaskNodeStat; 36 class RTTaskNodeContext { 37 public: 38 explicit RTTaskNodeContext( 39 std::string nodeName, 40 INT32 nodeId, 41 std::vector<RTStreamInfo *> *inputInfos, 42 std::vector<RTStreamInfo *> *outputInfos); 43 ~RTTaskNodeContext(); 44 45 RTTaskNodeContext(const RTTaskNodeContext&) = delete; 46 RTTaskNodeContext& operator=(const RTTaskNodeContext&) = delete; 47 48 RT_RET prepareForRun(RtMetaData* options); 49 RT_RET cleanupAfterRun(); 50 nodeName()51 const std::string& nodeName() const { return mNodeName; } nodeId()52 INT32 nodeId() const { return mNodeId; } suspend()53 void suspend() { mSuspend = true; } resume()54 void resume() { mSuspend = false; } 55 RT_RET flush(); isSuspend()56 bool isSuspend() { return mSuspend; } options()57 RtMetaData* options() { return mOptions; } 58 void sendInterrupt(std::string reason); 59 void cancelInterrupt(std::string reason); 60 void setOutputBufferListener(RTBufferListener *listener); 61 void setMaxBatchPrcoessSize(INT32 maxBatchSize); 62 INT32 getMaxBatchPrcoessSize(); 63 64 RTStreamInfo* getInputInfo(std::string streamType = "none"); 65 RTStreamInfo* getOutputInfo(std::string streamType = "none"); 66 67 RT_RET getPackets(std::list<RTMediaBuffer *> *packets, std::string streamType = "none"); 68 69 RT_BOOL hasInputStream(std::string streamType = "none"); 70 RT_BOOL hasOutputStream(std::string streamType = "none"); 71 INT32 inputQueueSize(std::string streamType = "none"); 72 RT_BOOL inputIsEmpty(std::string streamType = "none"); 73 RT_BOOL outputIsEmpty(std::string streamType = "none"); 74 75 RTMediaBuffer* inputHeadBuffer(std::string streamType = "none"); 76 RTMediaBuffer* dequeInputBuffer(std::string streamType = "none"); 77 RT_RET queueInputBuffer(RTMediaBuffer *packet, std::string streamTpye = "none"); 78 RTMediaBuffer* dequeOutputBuffer(RT_BOOL block = RT_TRUE, 79 UINT32 size = 0, 80 std::string streamType = "none"); 81 RT_RET queueOutputBuffer(RTMediaBuffer *packet, std::string streamType = "none"); 82 RT_RET getBufferStat(RTTaskNodeStat *stat); 83 84 RT_RET reallocOutputBuffers(INT32 wantSize, std::string streamType = "none"); 85 86 RT_RET attachOutStreamPool(RTMediaBufferPool *pool, std::string streamType = "none"); 87 RT_RET detachOutStreamPool(std::string streamType = "none"); 88 RT_RET pollOutputBuffer(RT_BOOL block = RT_TRUE, 89 UINT32 size = 0, 90 std::string streamType = "none"); 91 INT32 getOutputBufferSize(std::string streamType = "none"); 92 93 RT_RET dump(); 94 95 private: 96 std::vector<RTMediaBuffer *>* inputs(std::string streamType = "none"); 97 RTOutputStreamShared* outputs(std::string streamType = "none"); 98 99 private: 100 std::map<std::string, std::vector<RTMediaBuffer *>> mInputs; 101 std::map<std::string, RTOutputStreamShared *> mOutputs; 102 RtMetaData *mOptions; 103 INT32 mNodeId; 104 std::string mNodeName; 105 bool mSuspend = false; 106 INT32 mMaxBatchProcessSize = 4; 107 std::vector<RTStreamInfo *> *mInputInfos; 108 std::vector<RTStreamInfo *> *mOutputInfos; 109 RtMutex mInputMutex; 110 }; 111 112 #endif // SRC_RT_TASK_TASK_GRAPH_RTTASKNODECONTEXT_H_ 113 114