x265-1.7版本-common/framedata.h注释

本文深入解析了x265编码器中帧数据结构的组成和作用,包括slice数据、SAO参数、配置参数、重构帧数据等关键组件,以及如何在编码过程中管理和维护这些数据。

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

/*****************************************************************************
* Copyright (C) 2013 x265 project
*
* Author: 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_FRAMEDATA_H
#define X265_FRAMEDATA_H

#include "common.h"
#include "slice.h"
#include "cudata.h"

namespace x265 {
// private namespace

class PicYuv;
class JobProvider;

/* Per-frame data that is used during encodes and referenced while the picture
 * is available for reference. A FrameData instance is attached to a Frame as it
 * comes out of the lookahead. Frames which are not being encoded do not have a
 * FrameData instance. These instances are re-used once the encoded frame has
 * no active references. They hold the Slice instance and the 'official' CTU
 * data structures. They are maintained in a free-list pool along together with
 * a reconstructed image PicYuv in order to conserve memory. */
class FrameData
{
public:

    Slice*         m_slice; //slice数据,在本类中会实例化
    SAOParam*      m_saoParam;
    x265_param*    m_param;  //配置参数

    FrameData*     m_freeListNext;
    PicYuv*        m_reconPic;     //重构帧数据首地址 (只是指针,指向 frame->m_reconPic)
    bool           m_bHasReferences; // 表示是否有帧参考它(如果后向帧不再参考它设为false) 如果是X265_TYPE_B(不可参考B帧) 设置为false 否则为true 在新来帧计算RPS时会用到(对已经确定RPS的帧,其状态是不可靠的) /* used during DPB/RPS updates */
    int            m_frameEncoderID; //当前任务的job id  /* the ID of the FrameEncoder encoding this frame */
    JobProvider*   m_jobProvider;   //当前帧所在的线程位置

    CUDataMemPool  m_cuMemPool;  //存储一帧CTU的全部空间
    CUData*        m_picCTU;     //存储当前帧的全部CTU (空间为一帧CTU个数,在本类中会实例化)

    /* Rate control data used during encode and by references */
    struct RCStatCU
    {
        uint32_t totalBits;     /* total bits to encode this CTU */
        uint32_t vbvCost;       /* sum of lowres costs for 16x16 sub-blocks */
        uint32_t intraVbvCost;  /* sum of lowres intra costs for 16x16 sub-blocks */
        uint64_t avgCost[4];    /* stores the avg cost of CU's in frame for each depth */
        uint32_t count[4];      /* count and avgCost only used by Analysis at RD0..4 */
        double   baseQp;        /* Qp of Cu set from RateControl/Vbv (only used by frame encoder) */
    };
    
    struct RCStatRow//只在FrameData类中应用
    {
        uint32_t numEncodedCUs; /* ctuAddr of last encoded CTU in row */
        uint32_t encodedBits;   /* sum of 'totalBits' of encoded CTUs */
        uint32_t satdForVbv;    //在Lookahead::getEstimatedPictureCost函数中存储每个CTU行对应所有8x8块的cost累加值 /* sum of lowres (estimated) costs for entire row */
        uint32_t intraSatdForVbv;//在Lookahead::getEstimatedPictureCost函数中存储每个CTU行对应所有8x8块的intracost累加值  /* sum of lowres (estimated) intra costs for entire row */
        uint32_t diagSatd;
        uint32_t diagIntraSatd;
        double   diagQp;
        double   diagQpScale;
        double   sumQpRc;
        double   sumQpAq;
    };

    RCStatCU*      m_cuStat; //申请空间为一帧CTU个数???
    RCStatRow*     m_rowStat;//申请空间为一帧CTU行数???

    double         m_avgQpRc;    /* avg QP as decided by rate-control */
    double         m_avgQpAq;    /* avg QP as decided by AQ in addition to rate-control */
    double         m_rateFactor; /* calculated based on the Frame QP */
    /** 函数功能    :初始化
    /*  调用范围    :只在Frame::allocEncodeData函数中被调用
    */
    FrameData();
    /** 函数功能    :申请一帧CTU的存储空间,初始化CTU、初始化统计信息
    /*  调用范围    :只在Frame::allocEncodeData函数中被调用
    * \返回值       :申请空间成功为ture,否则为false
    */
    bool create(x265_param *param, const SPS& sps);
    /** 函数功能    :初始化统计信息为0
    /*  调用范围    :只在FrameData::create和Frame::reinit函数中被调用
    * \返回值       :null
    */
    void reinit(const SPS& sps);
    /** 函数功能    :释放内存
    /*  调用范围    :只在Frame::destroy()和DPB::~DPB()函数中被调用
    */
    void destroy();
    /** 函数功能    :获取在当前帧对应号的CTU   
    * \参数  ctuAddr: CTU在帧中的编号 */
    CUData* getPicCTU(uint32_t ctuAddr) { return &m_picCTU[ctuAddr]; }
};
}

#endif // ifndef X265_FRAMEDATA_H


<think>好的,用户遇到了一个编译错误,具体是找不到`pcl-1.7/pcl/visualization/cloud_viewer.h`这个头文件。我需要先分析可能的原因,然后给出解决方案。 首先,用户提供的错误信息显示包含路径中有`pcl-1.7`,这可能意味着他们在代码中直接使用了带有版本号的路径。而PCL库在安装时通常不会在头文件路径中包含版本号,比如常见的路径是`/usr/include/pcl-1.12/pcl/...`,但代码中的包含路径可能不正确。 接下来,我需要考虑几个可能的原因: 1. **PCL未安装或版本不匹配**:用户可能没有安装PCL,或者安装的版本与代码中指定的版本1.7)不一致。例如,系统安装的是PCL 1.12,但代码里硬编码了1.7的路径。 2. **头文件路径配置问题**:编译时没有正确指定PCL的头文件路径,导致编译器找不到对应的文件。这可能涉及到CMakeLists.txt中的include_directories设置。 3. **代码中包含路径错误**:代码中直接写了`#include <pcl-1.7/pcl/visualization/cloud_viewer.h>`,而实际安装的路径可能是`pcl-1.12`或者不带版本号,这时候需要修改代码中的包含路径。 接下来,我需要给出具体的解决步骤: - **确认PCL安装情况**:用户需要检查是否安装了PCL,以及安装的版本。可以通过包管理器查询,比如`apt list --installed | grep pcl`。 - **调整包含路径**:如果PCL已安装但版本不同,建议修改代码中的包含语句,去掉版本号,比如`#include <pcl/visualization/cloud_viewer.h>`,并在CMake中正确链接PCL库。 - **更新CMakeLists.txt**:确保CMake正确找到PCL的依赖,使用`find_package(PCL REQUIRED)`并包含相关目录和链接库。 此外,可能需要考虑用户的环境,比如是否使用了ROS自带的PCL,或者在非ROS环境下使用。如果用户使用的是ROS,可能需要检查工作区的依赖配置,或者安装对应版本的PCL。 最后,需要提醒用户检查代码中的硬编码路径,避免未来出现类似问题,并建议使用动态查找库的方式,比如通过CMake的find_package来管理依赖。</think>### 错误原因分析 你遇到的错误是编译器在编译时找不到 `pcl/visualization/cloud_viewer.h` 头文件。具体原因可能有以下几点: 1. **PCL 库未正确安装** 代码中引用了 PCL (Point Cloud Library) 的 `cloud_viewer.h` 头文件,但系统中未安装 PCL 库,或安装的版本与代码要求的版本(如 1.7)不匹配。 2. **头文件路径配置错误** - 代码中的 `#include` 路径写成了硬编码的 `pcl-1.7/pcl/...`,而实际安装的 PCL 头文件路径可能不包含版本号(如 `/usr/include/pcl-1.12/pcl/...`)。 - CMake 未正确配置 PCL 的包含路径。 3. **版本冲突** 如果系统中安装了多个 PCL 版本(例如 ROS 自带的 PCL 和手动安装的 PCL),可能导致路径混淆。 --- ### 解决方案 #### 1. 确认 PCL 是否安装 首先检查系统中是否安装了 PCL 库: ```bash # Ubuntu/Debian 检查已安装的 PCL 包 dpkg -l | grep pcl # 查看头文件路径是否存在 ls /usr/include/pcl-* ``` - 如果未安装 PCL,执行以下命令安装: ```bash sudo apt install libpcl-dev # 安装默认版本(如 1.12) ``` #### 2. 修改代码中的头文件路径 将代码中的硬编码路径从: ```cpp #include <pcl-1.7/pcl/visualization/cloud_viewer.h> ``` 改为通用路径(去掉版本号): ```cpp #include <pcl/visualization/cloud_viewer.h> ``` #### 3. 配置 CMake 正确链接 PCL 在 `CMakeLists.txt` 中添加以下内容: ```cmake find_package(PCL REQUIRED COMPONENTS common visualization) # 查找 PCL 库 include_directories(${PCL_INCLUDE_DIRS}) # 添加头文件路径 target_link_libraries(your_target ${PCL_LIBRARIES}) # 链接 PCL 库 ``` #### 4. 检查依赖版本兼容性 如果代码依赖 PCL 1.7 的特定功能,而系统安装的是较新版本(如 1.12): - **方法一**:安装 PCL 1.7(需手动编译): ```bash # 从源码编译安装 PCL 1.7 git clone -b pcl-1.7.2 https://github.com/PointCloudLibrary/pcl.git cd pcl && mkdir build && cd build cmake .. && make -j4 sudo make install ``` - **方法二**:调整代码以适配新版本 PCL(推荐),例如: - 替换已弃用的函数(如 `pcl::visualization::CloudViewer` 在更高版本中被 `pcl::visualization::PCLVisualizer` 取代)。 - 参考 [PCL 版本迁移指南](https://github.com/PointCloudLibrary/pcl/wiki/How-to-update-your-code-from-PCL-1.7-to-PCL-1.8)。 #### 5. ROS 用户注意事项 如果项目基于 ROS(如 ROS Melodic 或 Noetic): - ROS 通常自带特定版本的 PCL(如 ROS Noetic 默认使用 PCL 1.10),需确保 `package.xml` 声明依赖: ```xml <depend>libpcl-all</depend> ``` - 清理并重新编译项目: ```bash cd ~/catkin_ws catkin clean # 清除旧编译文件 catkin_make # 重新编译 ``` --- ### 附加说明 - **路径中避免空格**:项目路径(如 `/home/csh/catkin hw4`)中的空格可能导致编译问题,建议重命名为 `catkin_hw4`。 - **环境变量**:如果手动安装了 PCL,确保 `LD_LIBRARY_PATH` 包含库路径: ```bash export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH ``` --- ### 相关扩展问题 1. **如何在同一系统中管理多个 PCL 版本?** 可使用符号链接或 `update-alternatives` 动态切换版本,或通过 `Docker` 隔离环境。 2. **CMake 报错 `Could NOT find PCL` 怎么办?** 指定 PCL 的安装路径: ```cmake set(PCL_DIR "/path/to/pcl/share/pcl-1.12") find_package(PCL REQUIRED) ``` 3. **如何调试头文件搜索路径?** 在终端执行以下命令查看编译器搜索路径: ```bash echo | gcc -E -Wp,-v - # 查看 C 头文件路径 echo | g++ -x c++ -E -Wp,-v - # 查看 C++ 头文件路径 ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值