x265-1.8版本-common/wavefront.cpp注释
生活随笔
收集整理的這篇文章主要介紹了
x265-1.8版本-common/wavefront.cpp注释
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
注:問號以及未注釋部分 會在x265-1.9版本內更新
/****************************************************************************** Copyright (C) 2013 x265 project** Authors: Steve Borho <steve@borho.org>** This program is free software; you can redistribute it and/or modify* it under the terms of the GNU General Public License as published by* the Free Software Foundation; either version 2 of the License, or* (at your option) any later version.** This program is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the* GNU General Public License for more details.** You should have received a copy of the GNU General Public License* along with this program; if not, write to the Free Software* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.** This program is also available under a commercial proprietary license.* For more information, contact us at license @ x265.com*****************************************************************************/#include "threadpool.h" #include "threading.h" #include "wavefront.h" #include "common.h"namespace X265_NS { // x265 private namespace /** 函數功能 : 初始化WaveFront /* 調用范圍 : 只在FrameEncoder::init函數中被調用 * \參數 numRows : 一幀的CTU行數*2 * 返回值 : 成功返回ture 失敗返回 false **/ bool WaveFront::init(int numRows) {m_numRows = numRows;//一幀CTU行數*2m_numWords = (numRows + 31) >> 5;//map占用的字節數目m_internalDependencyBitmap = X265_MALLOC(uint32_t, m_numWords);if (m_internalDependencyBitmap)memset((void*)m_internalDependencyBitmap, 0, sizeof(uint32_t) * m_numWords);m_externalDependencyBitmap = X265_MALLOC(uint32_t, m_numWords);if (m_externalDependencyBitmap)memset((void*)m_externalDependencyBitmap, 0, sizeof(uint32_t) * m_numWords);return m_internalDependencyBitmap && m_externalDependencyBitmap; } /** 函數功能 : 釋放內存 析構函數 /* 調用范圍 : 只在~FrameEncoder()函數中被調用 **/ WaveFront::~WaveFront() {x265_free((void*)m_internalDependencyBitmap);x265_free((void*)m_externalDependencyBitmap); } /** 函數功能 : 將當前WPPmap全部初始化為不可執行 /* 調用范圍 : 只在FrameEncoder::compressFrame()函數中被調用 * \返回 : null * */ void WaveFront::clearEnabledRowMask() {memset((void*)m_externalDependencyBitmap, 0, sizeof(uint32_t) * m_numWords);memset((void*)m_internalDependencyBitmap, 0, sizeof(uint32_t) * m_numWords); } /** 函數功能 : 將當前row對應位置的map置為1 標記可以執行 /* 調用范圍 : 只在enqueueRowEncoder和enqueueRowFilter函數中被調用 * \參數 row : CTU行號*2 + x x= 0 為 enqueueRowEncoder x= 1 為enqueueRowFilter * \返回 : null* */ void WaveFront::enqueueRow(int row) {uint32_t bit = 1 << (row & 31);//(row & 31) 表示當前row在當前組(32個row行為一組)的標號 1 << (row & 31) 表示 其具體位置: 如 組內偏移地址為(0~31)對應(1~2^31)ATOMIC_OR(&m_internalDependencyBitmap[row >> 5], bit);//m_internalDependencyBitmap[row >> 5] 表示其組位置 與bit后對應位置置為1 } /** 函數功能 : 將當前row對應位置的map置為1 標記可以執行 /* 調用范圍 : 只在enableRowEncoder和enableRowFilter函數中被調用 * \參數 row : CTU行號*2 + x x= 0 為 enableRowEncoder x= 1 為enableRowFilter * \返回 : null* */ void WaveFront::enableRow(int row) {uint32_t bit = 1 << (row & 31);//(row & 31) 表示當前row在當前組(32個row行為一組)的標號 1 << (row & 31) 表示 其具體位置: 如 組內偏移地址為(0~31)對應(1~2^31)ATOMIC_OR(&m_externalDependencyBitmap[row >> 5], bit);//m_externalDependencyBitmap[row >> 5] 表示其組位置 與bit后對應位置置為1 } /** 函數功能 : 將外部map全部標記為可執行 /* 調用范圍 : 無調用位置 * \返回 : null* */ void WaveFront::enableAllRows() {memset((void*)m_externalDependencyBitmap, ~0, sizeof(uint32_t) * m_numWords); } /** 函數功能 : 將當前row對應位置的map置為0 標記可以執行 /* 調用范圍 : 只在processRowEncoder函數中被調用 * \參數 row : CTU行號*2 + x x= 0 為 enableRowEncoder x= 1 為enableRowFilter * \返回 : 一般返回false* */ bool WaveFront::dequeueRow(int row) {uint32_t bit = 1 << (row & 31);//(row & 31) 表示當前row在當前組(32個row行為一組)的標號 1 << (row & 31) 表示 其具體位置: 如 組內偏移地址為(0~31)對應(1~2^31)return !!(ATOMIC_AND(&m_internalDependencyBitmap[row >> 5], ~bit) & bit);//m_externalDependencyBitmap[row >> 5] 表示其組位置 將對應位置的map標記為0 } /** 函數功能 : 觸發WPP(在threadMain()主動發起) 只進行處理一個CTU行即退出(不一定執行完畢)(其它CTU需要重新觸發) /* 調用范圍 : 只在WorkerThread::threadMain()(在compressFrame()、processRowEncoder通過tryWakeOne()中觸發執行) * \參數 threadId : 當前的內核號 * \返回 : null * */ void WaveFront::findJob(int threadId) {unsigned long id;//用于獲取組內地址/* Loop over each word until all available rows are finished */for (int w = 0; w < m_numWords; w++)//遍歷所有的CTU組 (32rows(16CTU行)一組){uint32_t oldval = m_internalDependencyBitmap[w] & m_externalDependencyBitmap[w];//判讀當前組是否有CTU行可執行 (其當前幀和refs的參考塊都準備好)while (oldval)//遍歷CTU行{CTZ(id, oldval);// 返回數值x從低位起 有多個連續0的個數 如 0:0 1:0 2(10):1 3(11):0 4(100):2 5(101):0 6(110):1 7(111):0 8(1000):3 優先低行先運行uint32_t bit = 1 << id;//其具體位置: 如 組內偏移地址為(0~31)對應(1~2^31)if (ATOMIC_AND(&m_internalDependencyBitmap[w], ~bit) & bit)//判斷是否可執行 并清除當前位置的標記為0(防止重復觸發相同行,如果編碼CTU行時,不符合規則提前跳出,后序會再次觸發) 注意:ATOMIC_AND(&m_internalDependencyBitmap[w], ~bit) 返回m_internalDependencyBitmap[w]原來的值再更新{/* we cleared the bit, we get to process the row */processRow(w * 32 + id, threadId);//執行具體CTU行(編碼或者濾波)m_helpWanted = true;//有可執行CTU行 置為truereturn; //退出 只執行一個CTU行/* check for a higher priority task */}oldval = m_internalDependencyBitmap[w] & m_externalDependencyBitmap[w];//判讀當前組是否有CTU行可執行 (其當前幀和refs的參考塊都準備好)}}m_helpWanted = false;//無可執行CTU行 置為false } }
?
總結
以上是生活随笔為你收集整理的x265-1.8版本-common/wavefront.cpp注释的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 探秘Hadoop生态6:Hive技术初探
- 下一篇: Failed to create Ana