1 /*****************************************************************************
2 * Copyright (C) 2013 x265 project
4 * Authors: Deepthi Nandakumar <deepthi@multicorewareinc.com>
5 * Steve Borho <steve@borho.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
21 * This program is also available under a commercial proprietary license.
22 * For more information, contact us at license @ x265.com.
23 *****************************************************************************/
25 #ifndef X265_ANALYSIS_H
26 #define X265_ANALYSIS_H
43 class Analysis
: public Search
60 PRED_INTRA_NxN
, /* 4x4 intra PU blocks for 8x8 CU */
61 PRED_LOSSLESS
, /* lossless encode of best mode */
67 Mode pred
[MAX_PRED_TYPES
];
70 CUDataMemPool cuMemPool
;
73 ModeDepth m_modeDepth
[NUM_CU_DEPTH
];
77 /* Analysis data for load/save modes, keeps getting incremented as CTU analysis proceeds and data is consumed or read */
78 analysis_intra_data
* m_reuseIntraDataCTU
;
79 analysis_inter_data
* m_reuseInterDataCTU
;
81 bool create(ThreadLocalData
* tld
);
83 Mode
& compressCTU(CUData
& ctu
, Frame
& frame
, const CUGeom
& cuGeom
, const Entropy
& initialContext
);
87 /* mode analysis distribution */
89 volatile int m_numAcquiredJobs
;
90 volatile int m_numCompletedJobs
;
92 Event m_modeCompletionEvent
;
93 bool findJob(int threadId
);
94 void parallelModeAnalysis(int threadId
, int jobId
);
95 void parallelME(int threadId
, int meId
);
97 /* full analysis for an I-slice CU */
98 void compressIntraCU(const CUData
& parentCTU
, const CUGeom
& cuGeom
, uint32_t &zOrder
);
100 /* full analysis for a P or B slice CU */
101 void compressInterCU_dist(const CUData
& parentCTU
, const CUGeom
& cuGeom
);
102 void compressInterCU_rd0_4(const CUData
& parentCTU
, const CUGeom
& cuGeom
);
103 void compressInterCU_rd5_6(const CUData
& parentCTU
, const CUGeom
& cuGeom
);
105 /* measure merge and skip */
106 void checkMerge2Nx2N_rd0_4(Mode
& skip
, Mode
& merge
, const CUGeom
& cuGeom
);
107 void checkMerge2Nx2N_rd5_6(Mode
& skip
, Mode
& merge
, const CUGeom
& cuGeom
);
109 /* measure inter options */
110 void checkInter_rd0_4(Mode
& interMode
, const CUGeom
& cuGeom
, PartSize partSize
);
111 void checkInter_rd5_6(Mode
& interMode
, const CUGeom
& cuGeom
, PartSize partSize
, bool bMergeOnly
);
113 void checkBidir2Nx2N(Mode
& inter2Nx2N
, Mode
& bidir2Nx2N
, const CUGeom
& cuGeom
);
115 /* encode current bestMode losslessly, pick best RD cost */
116 void tryLossless(const CUGeom
& cuGeom
);
118 /* add the RD cost of coding a split flag (0 or 1) to the given mode */
119 void addSplitFlagCost(Mode
& mode
, uint32_t depth
);
121 /* update CBF flags and QP values to be internally consistent */
122 void checkDQP(CUData
& cu
, const CUGeom
& cuGeom
);
124 /* work-avoidance heuristics for RD levels < 5 */
125 uint32_t topSkipMinDepth(const CUData
& parentCTU
, const CUGeom
& cuGeom
);
126 bool recursionDepthCheck(const CUData
& parentCTU
, const CUGeom
& cuGeom
, const Mode
& bestMode
);
128 /* generate residual and recon pixels for an entire CTU recursively (RD0) */
129 void encodeResidue(const CUData
& parentCTU
, const CUGeom
& cuGeom
);
131 /* check whether current mode is the new best */
132 inline void checkBestMode(Mode
& mode
, uint32_t depth
)
134 ModeDepth
& md
= m_modeDepth
[depth
];
137 if (mode
.rdCost
< md
.bestMode
->rdCost
)
145 struct ThreadLocalData
149 void destroy() { analysis
.destroy(); }
154 #endif // ifndef X265_ANALYSIS_H