注:问号以及未注释部分 会在x265-1.9版本内更新
/*****************************************************************************
* Copyright (C) 2015 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_PICYUV_H
#define X265_PICYUV_H
#include "common.h"
#include "md5.h"
#include "x265.h"
namespace X265_NS {
// private namespace
class ShortYuv;
struct SPS;
class PicYuv
{
public:
pixel* m_picBuf[3]; // 申请buf的首地址(分别表示Y、U、V) full allocated buffers, including margins
pixel* m_picOrg[3]; // 对应数据的首地址(首地址直接是原始数据,此处只是一个指针,m_picBuf的偏移地址)pointers to plane starts
uint32_t m_picWidth; //源图像宽度
uint32_t m_picHeight; //源图像高度
intptr_t m_stride; //亮度步长:(numCuInWidth * g_maxCUSize) + (m_lumaMarginX << 1); numCuInWidth:不够LCU的补全一个LCU
intptr_t m_strideC; //色度步长:((numCuInWidth * g_maxCUSize) >> m_hChromaShift) + (m_chromaMarginX * 2);
uint32_t m_picCsp; //图像取样格式:420、444:400
uint32_t m_hChromaShift;//根据图像格式,色度宽度需要移位个数 如420格式 就是1
uint32_t m_vChromaShift;//根据图像格式,色度高度需要移位个数 如420格式 就是1
/* these four buffers are owned by the top-level encoder */
//在整个编码器中只申请一次内存,然后将指针赋值到Encoder中,其它的都从Encoder中获取指针
/*如:一幅图像416x240 总过有7x4个LCU
m_cuOffsetY[0] = 0 m_cuOffsetY[1] = 64 m_cuOffsetY[2]= 128 m_cuOffsetY[7] = 40960 = 640*64 (640是步长含有扩边值)
m_cuOffsetC[0] = 0 m_cuOffsetC[1] = 32 m_cuOffsetC[2]= 64 m_cuOffsetC[7] = 13312 = 416*64 (416是步长含有扩边值)
m_buOffsetY[0] = 0 m_buOffsetY[1] = 4 m_buOffsetY[2]= 2560 (按照4x4块计算 zigzag排序 2560 = 640*4)
m_buOffsetC[0] = 0 m_buOffsetC[1] = 2 m_buOffsetY[2]= 832 (按照2x2块计算 zigzag排序 832 = 416*2)
**/
intptr_t* m_cuOffsetY; //申请空间为一帧LCU个数,按照行列对应亮度LCU的pixel地址
intptr_t* m_cuOffsetC; //申请空间为一帧LCU个数,按照行列对应色度LCU的pixel地址
intptr_t* m_buOffsetY; //申请空间为一个LCU的part个数(默认256个4x4),为当前亮度位置与LCU首地址的偏移地址 (按照zigzag4x4排序)
intptr_t* m_buOffsetC; //申请空间为一个LCU的part个数(默认256个4x4),为当前色度位置与LCU首地址的偏移地址 (按照zigzag2x2排序)
uint32_t m_lumaMarginX; //宽度左右各扩边值:g_maxCUSize + 32; 64+32 ?????为什么这么扩边
uint32_t m_lumaMarginY; //高度上下各扩边值:g_maxCUSize + 16; 64+16 ?????为什么这么扩边
uint32_t m_chromaMarginX;//色度扩边值为:m_lumaMarginX
uint32_t m_chromaMarginY;//色度扩边值为:m_lumaMarginY >> m_vChromaShift
/** 函数功能 :初始化PicYuv
* \返回值 :null */
PicYuv();
/** 函数功能 : 申请视频帧yuv内存
/* 调用范围 : 只在Frame::create和Frame::allocEncodeData函数中被调用(分别申请原始帧和重构帧内存)
* \参数 picWidth : 图像宽度
* \参数 picHeight : 图像高度
* \参数 picCsp : 图像采样格式
* 返回值 : 成功true失败false**/
bool create(uint32_t picWidth, uint32_t picHeight, uint32_t csp);
/** 函数功能 : 创建m_cuOffsetY等offset地址信息
/* 调用范围 : 只在Encoder::encode函数中被调用
* \参数 sps : sps信息(含有视频信息)
* 返回值 : 成功返回true,失败返回false
**/
bool createOffsets(const SPS& sps);
/** 函数功能 :释放内存
/* 调用范围 :只在void Frame::destroy()和~DPB()函数中被调用
* \返回值 :null
*/
void destroy();
void copyFromPicture(const x265_picture&, int padx, int pady);
intptr_t getChromaAddrOffset(uint32_t ctuAddr, uint32_t absPartIdx) const { return m_cuOffsetC[ctuAddr] + m_buOffsetC[absPartIdx]; }
/* get pointer to CTU start address */
pixel* getLumaAddr(uint32_t ctuAddr) { return m_picOrg[0] + m_cuOffsetY[ctuAddr]; }
pixel* getCbAddr(uint32_t ctuAddr) { return m_picOrg[1] + m_cuOffsetC[ctuAddr]; }
pixel* getCrAddr(uint32_t ctuAddr) { return m_picOrg[2] + m_cuOffsetC[ctuAddr]; }
pixel* getChromaAddr(uint32_t chromaId, uint32_t ctuAddr) { return m_picOrg[chromaId] + m_cuOffsetC[ctuAddr]; }
pixel* getPlaneAddr(uint32_t plane, uint32_t ctuAddr) { return m_picOrg[plane] + (plane ? m_cuOffsetC[ctuAddr] : m_cuOffsetY[ctuAddr]); }
const pixel* getLumaAddr(uint32_t ctuAddr) const { return m_picOrg[0] + m_cuOffsetY[ctuAddr]; }
const pixel* getCbAddr(uint32_t ctuAddr) const { return m_picOrg[1] + m_cuOffsetC[ctuAddr]; }
const pixel* getCrAddr(uint32_t ctuAddr) const { return m_picOrg[2] + m_cuOffsetC[ctuAddr]; }
const pixel* getChromaAddr(uint32_t chromaId, uint32_t ctuAddr) const { return m_picOrg[chromaId] + m_cuOffsetC[ctuAddr]; }
const pixel* getPlaneAddr(uint32_t plane, uint32_t ctuAddr) const { return m_picOrg[plane] + (plane ? m_cuOffsetC[ctuAddr] : m_cuOffsetY[ctuAddr]); }
/* get pointer to CU start address */
/** 函数功能 :返回当前的LCU下当前zigzag标号对应的亮度pixel地址
* \参数 cuAddr :CTU在帧中的编号
* \参数 absPartIdx :当前CU在LCU中4x4 zizag地址
* \返回值 :返回当前的LCU下当前zigzag标号对应的亮度pixel地址**/
pixel* getLumaAddr(uint32_t ctuAddr, uint32_t absPartIdx) { return m_picOrg[0] + m_cuOffsetY[ctuAddr] + m_buOffsetY[absPartIdx]; }
/** 函数功能 :返回当前的LCU下当前zigzag标号对应的色度pixel地址
* \参数 cuAddr :CTU在帧中的编号
* \参数 absPartIdx :当前CU在LCU中4x4 zizag地址
* \返回值 :返回当前的LCU下当前zigzag标号对应的色度pixel地址**/
pixel* getCbAddr(uint32_t ctuAddr, uint32_t absPartIdx) { return m_picOrg[1] + m_cuOffsetC[ctuAddr] + m_buOffsetC[absPartIdx]; }
/** 函数功能 :返回当前的LCU下当前zigzag标号对应的色度pixel地址
* \参数 cuAddr :CTU在帧中的编号
* \参数 absPartIdx :当前CU在LCU中4x4 zizag地址
* \返回值 :返回当前的LCU下当前zigzag标号对应的色度pixel地址**/
pixel* getCrAddr(uint32_t ctuAddr, uint32_t absPartIdx) { return m_picOrg[2] + m_cuOffsetC[ctuAddr] + m_buOffsetC[absPartIdx]; }
pixel* getChromaAddr(uint32_t chromaId, uint32_t ctuAddr, uint32_t absPartIdx) { return m_picOrg[chromaId] + m_cuOffsetC[ctuAddr] + m_buOffsetC[absPartIdx]; }
/** 函数功能 :返回当前CU在数据帧的数据亮度首地址
* \参数 cuAddr :CTU在帧中的编号
* \参数 absPartIdx :当前CU在LCU中4x4 zizag地址
* \返回值 :返回当前CU在数据帧的数据亮度首地址**/
const pixel* getLumaAddr(uint32_t ctuAddr, uint32_t absPartIdx) const { return m_picOrg[0] + m_cuOffsetY[ctuAddr] + m_buOffsetY[absPartIdx]; }
/** 函数功能 :返回当前CU在数据帧的数据cb首地址
* \参数 cuAddr :CTU在帧中的编号
* \参数 absPartIdx :当前CU在LCU中4x4 zizag地址
* \返回值 :返回当前CU在数据帧的数据cb首地址**/
const pixel* getCbAddr(uint32_t ctuAddr, uint32_t absPartIdx) const { return m_picOrg[1] + m_cuOffsetC[ctuAddr] + m_buOffsetC[absPartIdx]; }
/** 函数功能 :返回当前CU在数据帧的数据cr首地址
* \参数 cuAddr :CTU在帧中的编号
* \参数 absPartIdx :当前CU在LCU中4x4 zizag地址
* \返回值 :返回当前CU在数据帧的数据cr首地址**/
const pixel* getCrAddr(uint32_t ctuAddr, uint32_t absPartIdx) const { return m_picOrg[2] + m_cuOffsetC[ctuAddr] + m_buOffsetC[absPartIdx]; }
const pixel* getChromaAddr(uint32_t chromaId, uint32_t ctuAddr, uint32_t absPartIdx) const { return m_picOrg[chromaId] + m_cuOffsetC[ctuAddr] + m_buOffsetC[absPartIdx]; }
};
void updateChecksum(const pixel* plane, uint32_t& checksumVal, uint32_t height, uint32_t width, intptr_t stride, int row, uint32_t cuHeight);
void updateCRC(const pixel* plane, uint32_t& crcVal, uint32_t height, uint32_t width, intptr_t stride);
void crcFinish(uint32_t & crc, uint8_t digest[16]);
void checksumFinish(uint32_t checksum, uint8_t digest[16]);
void updateMD5Plane(MD5Context& md5, const pixel* plane, uint32_t width, uint32_t height, intptr_t stride);
}
#endif // ifndef X265_PICYUV_H