注:问号以及未注释部分 会在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行数*2
m_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行  置为true
return; //退出 只执行一个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注释相关推荐

  1. x265-1.8版本-common/wavefront.h注释

    注:问号以及未注释部分 会在x265-1.9版本内更新 /*********************************************************************** ...

  2. x265-1.8版本-common/pixel.cpp注释

    注:问号以及未注释部分 会在x265-1.9版本内更新 /*********************************************************************** ...

  3. x265-1.7版本-common/pixel.cpp注释

    注:问号以及未注释部分 会在x265-1.8版本内更新  /********************************************************************** ...

  4. x265-1.7版本-common/intrapred.cpp注释

    注:问号以及未注释部分 会在x265-1.8版本内更新  /********************************************************************** ...

  5. x265-1.7版本-common/lowres.cpp注释

    注:问号以及未注释部分 会在x265-1.8版本内更新  /********************************************************************** ...

  6. x265-1.8版本-common/lowres.cpp注释

    注:问号以及未注释部分 会在x265-1.9版本内更新 /*********************************************************************** ...

  7. x265-1.8版本-encoder/frameencoder.cpp注释

    注:问号以及未注释部分 会在x265-1.9版本内更新 /*********************************************************************** ...

  8. x265-1.7版本-encoder/frameencoder.cpp注释

    注:问号以及未注释部分 会在x265-1.8版本内更新 /*********************************************************************** ...

  9. x265-1.8版本-encoder/dpb.cpp注释

    注:问号以及未注释部分 会在x265-1.9版本内更新 /*********************************************************************** ...

最新文章

  1. 如何实现一个可复用的分布式事务消息架构方案?
  2. ECS是阿里云提供的什么服务
  3. \pages\WxPay\WxPay.js
  4. mybatis 多表查询-多对多
  5. grDevices | 如何在图形中使用数学表达式作为标注文本
  6. 推进 DevSecOps 走向未来
  7. 计算机组成原理—数据的表示、运算与校验(思维导图)
  8. cloudflare免费设置_Cloudflare 入门教程:使用 Cloudflare 免费 CDN 加速 amp; 保护自己的网站...
  9. python怎么批量下载图片_python批量下载图片的三种方法
  10. 使用JPA @OneToMany关联时,@ JoinColumn和mappedBy有什么区别
  11. videojs中文文档
  12. 计算机毕业设计Java医院医患管理系统(系统+源码+mysql数据库+Lw文档)
  13. 盘点wps函数公式大全
  14. 怎样才是理想的程序员
  15. 【手把手教你】使用Logistic回归、LDA和QDA模型预测指数涨跌
  16. RV1109开发板ssh服务器移植到arm开发板
  17. Java开源JEE框架
  18. appdata文件夹有什么用途?C盘appdata可以删除吗?
  19. 学习html/css基础的重点笔记
  20. android 设置屏幕对比度,【Android】安卓调节屏幕亮度

热门文章

  1. Android实现仿QQ登录可编辑下拉菜单
  2. 现代企业管理的12个指南针
  3. 文本检测 论文阅读笔记之 Pixel-Anchor: A Fast Oriented Scene Text Detector with Combined Networks
  4. /home/ljx/miniconda3/compiler_compat/ld: cannot find crtbeginS.o: 没有那个文件或目录
  5. 【Python】丘比特之箭,一箭穿心,快去发给你心仪的人叭~
  6. 艾永亮:苹果缺乏创新能力?打造超级产品是未来增长的关键
  7. 你追逐梦想之前听到的十种谎言
  8. echarts饼图直观显示数值最实用的方式
  9. java中文逗号替换成英文逗号_word如何将大量英文逗号批量替换为中文逗号?
  10. 手把手教你用 Homer 处理 fNIRS 数据