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 * author: <rimon.xu@rock-chips.com> and <martin.cheng@rock-chips.com> 17 * date: 2020-04-03 18 * module: RTUVCGraph 19 */ 20 21 #ifndef SRC_RT_TASK_APP_GRAPH_RTUVCGRAPH_H_ 22 #define SRC_RT_TASK_APP_GRAPH_RTUVCGRAPH_H_ 23 24 #include "rt_header.h" 25 #include "RTTaskGraph.h" 26 27 #define NN_MODE_ST_ASTERIA "st_asteria" 28 #define NN_MODE_ROCKX "rockx" 29 30 #define RT_AI_TYPE_FACE_DETECT "face" 31 #define RT_AI_TYPE_FACE_LANDMARK "face_landmark" 32 #define RT_AI_TYPE_FACE_ATTRIBUTE "face_attribute" 33 #define RT_AI_TYPE_FACE_FEATURE "face_feature" 34 #define RT_AI_TYPE_FACE_DISTANCE "face_distance" 35 #define RT_AI_TYPE_BODY "body" 36 #define RT_AI_TYPE_HAND "hand" 37 #define RT_AI_TYPE_HAND_LANDMARK "hand_landmark" 38 39 #define RT_UVC_MODE_EPTZ "eptz" 40 #define RT_UVC_MODE_UVC "uvc" 41 #define RT_UVC_MODE_EPTZ_ZOOM "eptz_zoom" 42 #define RT_UVC_MODE_UVC_ZOOM "uvc_zoom" 43 44 typedef enum _RT_EPTZ_MODE { 45 RT_EPTZ_PAN = 0, 46 RT_EPTZ_TILT = 1, 47 RT_EPTZ_ROLL = 2, // no support now 48 RT_EPTZ_AUTO = 3, 49 } RT_EPTZ_MODE; 50 51 class RTUVCGraph { 52 public: 53 explicit RTUVCGraph(const char* tagName); 54 ~RTUVCGraph(); 55 56 RT_RET prepare(); 57 RT_RET start(); 58 RT_RET stop(); 59 60 RT_RET observeUVCOutputStream(std::function<RT_RET(RTMediaBuffer *)> streamCallback); 61 RT_RET observeNNOutputStream(std::function<RT_RET(RTMediaBuffer *)> streamCallback); 62 RT_RET observeMattingOutputStream(std::function<RT_RET(RTMediaBuffer *)> streamCallback); 63 RT_RET updateCameraParams(RtMetaData *params); 64 RT_RET updateEncoderParams(RtMetaData *params); 65 RT_RET updateNNParams(RtMetaData *params); 66 RT_RET setCameraParams(); 67 68 RT_RET enableEPTZ(RT_BOOL enableEPTZ); 69 RT_RET setZoom(float val); 70 RT_RET setEptz(RT_EPTZ_MODE mode, int val); 71 RT_RET openUVC(); 72 RT_RET closeUVC(); 73 RT_RET enableAIAlgorithm(std::string type); 74 RT_RET disableAIAlgorithm(std::string type); 75 76 RT_RET setAIAlgorithmHandle(void *handle); 77 78 RT_RET openAIMatting(); 79 RT_RET closeAIMatting(); 80 81 RT_RET waitUntilDone(); 82 getCtx()83 void *getCtx() { return mCtx; } 84 RT_RET selectLinkMode(); 85 RT_RET preload(RtMetaData *meta); 86 RT_RET invoke(INT32 cmd, void *data); 87 88 private: 89 RT_RET initialize(); 90 RT_RET deinitialize(); 91 92 RT_RET openAI(); 93 RT_RET closeAI(); 94 95 RT_RET setupGraphAndWaitDone(); 96 INT32 getDetectionByType(std::string type); 97 std::string getAIAlgorithmType(std::string type); 98 RT_RET updateAIAlgorithm(); 99 RT_RET setAIAlgorithm(RT_BOOL enable, std::string type); 100 RT_RET setZoomPtz(RT_BOOL isZoom); 101 102 static void* threadLoop(void* arg); 103 104 private: 105 void *mCtx; 106 std::function<RT_RET(RTMediaBuffer *)> mNNCallback; 107 std::function<RT_RET(RTMediaBuffer *)> mUVCCallback; 108 std::function<RT_RET(RTMediaBuffer *)> mMattingCallback; 109 std::map<std::string, RT_BOOL> mVendorDetections; 110 }; 111 112 #endif // SRC_RT_TASK_APP_GRAPH_RTUVCGRAPH_H_ 113