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

注:问号以及未注释部分 会在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
 *****************************************************************************/

#ifndef X265_WAVEFRONT_H
#define X265_WAVEFRONT_H

#include "common.h"
#include "threadpool.h"

namespace X265_NS {
// x265 private namespace

// Generic wave-front scheduler, manages busy-state of CU rows as a priority
// queue (higher CU rows have priority over lower rows)
//
// Derived classes must implement ProcessRow().
class WaveFront : public JobProvider//被FrameEncoder继承  用于WPP并行
{
private:

    // bitmaps of rows queued for processing, uses atomic intrinsics

    // Dependencies are categorized as internal and external. Internal dependencies
    // are caused by neighbor block availability.  External dependencies are generally
    // reference frame reconstructed pixels being available.
    uint32_t volatile *m_internalDependencyBitmap;//map 其对应位置为1 表示前面intra参考块已编码完毕,可以进行编码
    uint32_t volatile *m_externalDependencyBitmap;//map 其对应位置为1 表示当前行的外部参考块(如参考帧对应参考块)已经解决,可以进行编码

    // number of words in the bitmap
    int m_numWords;//map占用uint32_t数目 m_numWords = (numRows + 31) >> 5;

    int m_numRows;//一帧CTU行数*2  row*2 + x  x=0 为编码决策  x= 1 为滤波
    /* 加上当前视频的CTU行为: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 
    则分为两类:
    编码:0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 
    滤波:1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33
    m_numWords = (17*2+ 31) >> 5 = 2
    分为两组:
    编码:(0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30),(32) 分别对应map: m_internalDependencyBitmap[0]、m_internalDependencyBitmap[1];m_externalDependencyBitmap[0]、m_externalDependencyBitmap[1]
    滤波:(1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31),(33) 分别对应map: m_internalDependencyBitmap[0]、m_internalDependencyBitmap[1];m_externalDependencyBitmap[0]、m_externalDependencyBitmap[1]
    而其map对应32位中对应组内的32行
    **/

public:
    //构造函数 初始化null
    WaveFront()
        : m_internalDependencyBitmap(NULL)
        , m_externalDependencyBitmap(NULL)
    {}
    /** 函数功能       : 释放内存 析构函数
    /*  调用范围       : 只在~FrameEncoder()函数中被调用
    **/
    virtual ~WaveFront();

    // If returns false, the frame must be encoded in series.
    /** 函数功能       : 初始化WaveFront
    /*  调用范围       : 只在FrameEncoder::init函数中被调用
    * \参数 numRows    : 一帧的CTU行数*2
    *   返回值         : 成功返回ture 失败返回 false
    **/
    bool init(int numRows);

    // Enqueue a row to be processed (mark its internal dependencies as resolved).
    // A worker thread will later call processRow(row).
    // This provider must be enqueued in the pool before enqueuing a row
    /** 函数功能             : 将当前row对应位置的map置为1 标记可以执行
    /*  调用范围             : 只在enqueueRowEncoder和enqueueRowFilter函数中被调用
    * \参数 row              : CTU行号*2 + x  x= 0 为 enqueueRowEncoder  x= 1 为enqueueRowFilter
    * \返回                  : null* */
    void enqueueRow(int row);

    // Mark a row as no longer having internal dependencies resolved. Returns
    // true if bit clear was successful, false otherwise.
    /** 函数功能             : 将当前row对应位置的map置为0 标记可以执行
    /*  调用范围             : 只在processRowEncoder函数中被调用
    * \参数 row              : CTU行号*2 + x  x= 0 为 enableRowEncoder  x= 1 为enableRowFilter
    * \返回                  : 一般返回false* */
    bool dequeueRow(int row);

    // Mark the row's external dependencies as being resolved
    /** 函数功能             : 将当前row对应位置的map置为1 标记可以执行
    /*  调用范围             : 只在enableRowEncoder和enableRowFilter函数中被调用
    * \参数 row              : CTU行号*2 + x  x= 0 为 enableRowEncoder  x= 1 为enableRowFilter
    * \返回                  : null* */
    void enableRow(int row);

    // Mark all row external dependencies as being resolved. Some wavefront
    // implementations (lookahead, for instance) have no recon pixel dependencies.
    /** 函数功能             : 将外部map全部标记为可执行
    /*  调用范围             : 无调用位置
    * \返回                  : null* */
    void enableAllRows();

    // Mark all rows as having external dependencies which must be
    // resolved before each row may proceed.
    /** 函数功能             : 将当前WPPmap全部初始化为不可执行
    /*  调用范围             : 只在FrameEncoder::compressFrame()函数中被调用
    * \返回                  : null * */
    void clearEnabledRowMask();

    // WaveFront's implementation of JobProvider::findJob. Consults
    // m_queuedBitmap and calls ProcessRow(row) for lowest numbered queued row
    // processes available rows and returns when no work remains
    /** 函数功能             : 触发WPP(在threadMain()主动发起) 只进行处理一个CTU行即退出(不一定执行完毕)(其它CTU需要重新触发)
    /*  调用范围             : 只在WorkerThread::threadMain()(在compressFrame()、processRowEncoder通过tryWakeOne()中触发执行)
    * \参数 threadId         : 当前的内核号
    * \返回                  : null * */
    void findJob(int threadId);

    // Start or resume encode processing of this row, must be implemented by
    // derived classes.
    virtual void processRow(int row, int threadId) = 0;//虚函数 子类具体调用 执行具体CTU行(滤波或者编码)
};
} // end namespace X265_NS

#endif // ifndef X265_WAVEFRONT_H


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值