1 /*! 2 * \copy 3 * Copyright (c) 2009-2015, Cisco Systems 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * * Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 13 * * Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 * 31 * 32 * \file wels_task_management.h 33 * 34 * \brief interface for task management 35 * 36 * \date 5/14/2012 Created 37 * 38 ************************************************************************************* 39 */ 40 41 #ifndef _WELS_ENCODER_TASK_MANAGE_H_ 42 #define _WELS_ENCODER_TASK_MANAGE_H_ 43 44 #include "wels_common_basis.h" 45 #include "WelsLock.h" 46 #include "WelsThreadPool.h" 47 #include "wels_task_base.h" 48 49 namespace WelsEnc { 50 51 class IWelsTaskManage { 52 public: ~IWelsTaskManage()53 virtual ~IWelsTaskManage() { } 54 55 virtual WelsErrorType Init (sWelsEncCtx* pEncCtx) = 0; 56 virtual void Uninit() = 0; 57 InitFrame(const int32_t kiCurDid)58 virtual void InitFrame (const int32_t kiCurDid) {} 59 virtual WelsErrorType ExecuteTasks (const CWelsBaseTask::ETaskType iTaskType = CWelsBaseTask::WELS_ENC_TASK_ENCODING) 60 = 0; 61 62 static IWelsTaskManage* CreateTaskManage (sWelsEncCtx* pCtx, const int32_t iSpatialLayer, const bool bNeedLock); 63 64 virtual int32_t GetThreadPoolThreadNum() = 0; 65 }; 66 67 68 class CWelsTaskManageBase : public IWelsTaskManage, public WelsCommon::IWelsTaskSink { 69 public: 70 typedef CWelsNonDuplicatedList<CWelsBaseTask> TASKLIST_TYPE; 71 //typedef std::pair<int, int> SLICE_BOUNDARY_PAIR; 72 //typedef CWelsList<SLICE_BOUNDARY_PAIR> SLICE_PAIR_LIST; 73 74 CWelsTaskManageBase(); 75 virtual ~ CWelsTaskManageBase(); 76 77 virtual WelsErrorType Init (sWelsEncCtx* pEncCtx); 78 virtual void InitFrame (const int32_t kiCurDid = 0); 79 80 virtual WelsErrorType ExecuteTasks (const CWelsBaseTask::ETaskType iTaskType = CWelsBaseTask::WELS_ENC_TASK_ENCODING); 81 82 //IWelsTaskSink 83 virtual WelsErrorType OnTaskExecuted(); 84 virtual WelsErrorType OnTaskCancelled(); 85 86 int32_t GetThreadPoolThreadNum(); 87 88 protected: 89 virtual WelsErrorType CreateTasks (sWelsEncCtx* pEncCtx, const int32_t kiTaskCount); 90 91 WelsErrorType ExecuteTaskList(TASKLIST_TYPE** pTaskList); 92 93 protected: 94 sWelsEncCtx* m_pEncCtx; 95 WelsCommon::CWelsThreadPool* m_pThreadPool; 96 97 TASKLIST_TYPE* m_pcAllTaskList[CWelsBaseTask::WELS_ENC_TASK_ALL][MAX_DEPENDENCY_LAYER]; 98 TASKLIST_TYPE* m_cEncodingTaskList[MAX_DEPENDENCY_LAYER]; 99 TASKLIST_TYPE* m_cPreEncodingTaskList[MAX_DEPENDENCY_LAYER]; 100 int32_t m_iTaskNum[MAX_DEPENDENCY_LAYER]; 101 102 //SLICE_PAIR_LIST *m_cSliceList; 103 104 int32_t m_iThreadNum; 105 106 int32_t m_iWaitTaskNum; 107 WELS_EVENT m_hTaskEvent; 108 WELS_MUTEX m_hEventMutex; 109 WelsCommon::CWelsLock m_cWaitTaskNumLock; 110 111 private: 112 DISALLOW_COPY_AND_ASSIGN (CWelsTaskManageBase); 113 void OnTaskMinusOne(); 114 115 void Uninit(); 116 void DestroyTasks(); 117 void DestroyTaskList(TASKLIST_TYPE* pTargetTaskList); 118 119 int32_t m_iCurDid; 120 }; 121 122 class CWelsTaskManageOne : public CWelsTaskManageBase { 123 public: 124 CWelsTaskManageOne(); 125 virtual ~CWelsTaskManageOne(); 126 127 WelsErrorType Init (sWelsEncCtx* pEncCtx); 128 virtual WelsErrorType ExecuteTasks(const CWelsBaseTask::ETaskType iTaskType = CWelsBaseTask::WELS_ENC_TASK_ENCODING); 129 GetThreadPoolThreadNum()130 int32_t GetThreadPoolThreadNum() {return 1;}; 131 }; 132 133 } //namespace 134 #endif //header guard 135 136