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_encoder.h 33 * 34 * \brief interface for encoder tasks 35 * 36 * \date 07/06/2015 Created 37 * 38 ************************************************************************************* 39 */ 40 41 #ifndef _WELS_ENCODER_TASK_H_ 42 #define _WELS_ENCODER_TASK_H_ 43 44 #include "wels_task_base.h" 45 #include "encoder_context.h" 46 47 namespace WelsEnc { 48 49 extern int32_t WriteSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, uint8_t* pFrameBsBuffer, 50 const int32_t iSliceIdx, 51 int32_t& iSliceSize); 52 extern int32_t WriteSliceBs (sWelsEncCtx* pCtx,SWelsSliceBs* pSliceBs,const int32_t iSliceIdx, int32_t& iSliceSize); 53 54 class CWelsSliceEncodingTask : public CWelsBaseTask { 55 public: 56 CWelsSliceEncodingTask (WelsCommon::IWelsTaskSink* pSink, sWelsEncCtx* pCtx, const int32_t iSliceIdx); 57 virtual ~CWelsSliceEncodingTask(); 58 59 CWelsSliceEncodingTask* CreateSliceEncodingTask (sWelsEncCtx* pCtx, const int32_t iSliceIdx); 60 WelsErrorType SetBoundary (int32_t iStartMbIdx, int32_t iEndMbIdx); 61 62 virtual WelsErrorType Execute(); 63 virtual WelsErrorType InitTask(); 64 virtual WelsErrorType ExecuteTask(); 65 virtual void FinishTask(); 66 GetTaskType()67 virtual uint32_t GetTaskType() const { 68 return WELS_ENC_TASK_ENCODE_FIXED_SLICE; 69 } 70 protected: 71 WelsErrorType m_eTaskResult; 72 73 int32_t QueryEmptyThread (bool* pThreadBsBufferUsage); 74 75 sWelsEncCtx* m_pCtx; 76 SSliceThreadPrivateData* m_pPrivateData; 77 SLayerBSInfo* m_pLbi; 78 int32_t m_iStartMbIdx; 79 int32_t m_iEndMbIdx; 80 81 EWelsNalUnitType m_eNalType; 82 EWelsNalRefIdc m_eNalRefIdc; 83 bool m_bNeedPrefix; 84 uint32_t m_uiDependencyId; 85 86 SSlice* m_pSlice; 87 SWelsSliceBs* m_pSliceBs; 88 int32_t m_iSliceIdx; 89 int32_t m_iSliceSize; 90 int32_t m_iThreadIdx; 91 }; 92 93 class CWelsLoadBalancingSlicingEncodingTask : public CWelsSliceEncodingTask { 94 public: CWelsLoadBalancingSlicingEncodingTask(WelsCommon::IWelsTaskSink * pSink,sWelsEncCtx * pCtx,const int32_t iSliceIdx)95 CWelsLoadBalancingSlicingEncodingTask (WelsCommon::IWelsTaskSink* pSink, sWelsEncCtx* pCtx, const int32_t iSliceIdx) : CWelsSliceEncodingTask (pSink, pCtx, 96 iSliceIdx) { 97 }; 98 99 virtual WelsErrorType InitTask(); 100 virtual void FinishTask(); 101 GetTaskType()102 virtual uint32_t GetTaskType() const { 103 return WELS_ENC_TASK_ENCODE_SLICE_LOADBALANCING; 104 } 105 private: 106 int64_t m_iSliceStart; 107 }; 108 109 110 class CWelsConstrainedSizeSlicingEncodingTask : public CWelsLoadBalancingSlicingEncodingTask { 111 public: CWelsConstrainedSizeSlicingEncodingTask(WelsCommon::IWelsTaskSink * pSink,sWelsEncCtx * pCtx,const int32_t iSliceIdx)112 CWelsConstrainedSizeSlicingEncodingTask (WelsCommon::IWelsTaskSink* pSink, sWelsEncCtx* pCtx, 113 const int32_t iSliceIdx) : CWelsLoadBalancingSlicingEncodingTask (pSink, pCtx, iSliceIdx) { 114 }; 115 116 virtual WelsErrorType ExecuteTask(); 117 GetTaskType()118 virtual uint32_t GetTaskType() const { 119 return WELS_ENC_TASK_ENCODE_SLICE_SIZECONSTRAINED; 120 } 121 122 }; 123 124 125 class CWelsUpdateMbMapTask : public CWelsBaseTask { 126 public: 127 CWelsUpdateMbMapTask (WelsCommon::IWelsTaskSink* pSink, sWelsEncCtx* pCtx, const int32_t iSliceIdx); 128 virtual ~CWelsUpdateMbMapTask(); 129 130 virtual WelsErrorType Execute(); 131 GetTaskType()132 virtual uint32_t GetTaskType() const { 133 return WELS_ENC_TASK_UPDATEMBMAP; 134 } 135 protected: 136 sWelsEncCtx* m_pCtx; 137 int32_t m_iSliceIdx; 138 }; 139 140 } //namespace 141 #endif //header guard 142 143