Commit | Line | Data |
---|---|---|
72b9787e JB |
1 | /***************************************************************************** |
2 | * Copyright (C) 2013 x265 project | |
3 | * | |
4 | * Authors: Deepthi Nandakumar <deepthi@multicorewareinc.com> | |
5 | * Steve Borho <steve@borho.org> | |
6 | * | |
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. | |
11 | * | |
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. | |
16 | * | |
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. | |
20 | * | |
21 | * This program is also available under a commercial proprietary license. | |
22 | * For more information, contact us at license @ x265.com. | |
23 | *****************************************************************************/ | |
24 | ||
25 | #ifndef X265_ANALYSIS_H | |
26 | #define X265_ANALYSIS_H | |
27 | ||
28 | #include "common.h" | |
29 | #include "predict.h" | |
30 | #include "quant.h" | |
31 | #include "yuv.h" | |
32 | #include "shortyuv.h" | |
33 | #include "cudata.h" | |
34 | ||
35 | #include "entropy.h" | |
36 | #include "search.h" | |
37 | ||
38 | namespace x265 { | |
39 | // private namespace | |
40 | ||
41 | class Entropy; | |
42 | ||
43 | class Analysis : public Search | |
44 | { | |
45 | public: | |
46 | ||
47 | enum { | |
48 | PRED_MERGE, | |
49 | PRED_SKIP, | |
50 | PRED_INTRA, | |
51 | PRED_2Nx2N, | |
52 | PRED_Nx2N, | |
53 | PRED_2NxN, | |
54 | PRED_SPLIT, | |
55 | PRED_2NxnU, | |
56 | PRED_2NxnD, | |
57 | PRED_nLx2N, | |
58 | PRED_nRx2N, | |
59 | PRED_INTRA_NxN, /* 4x4 intra PU blocks for 8x8 CU */ | |
60 | PRED_LOSSLESS, /* lossless encode of best mode */ | |
61 | MAX_PRED_TYPES | |
62 | }; | |
63 | ||
64 | struct ModeDepth | |
65 | { | |
66 | Mode pred[MAX_PRED_TYPES]; | |
67 | Mode* bestMode; | |
68 | Yuv fencYuv; | |
69 | CUDataMemPool cuMemPool; | |
70 | }; | |
71 | ||
72 | ModeDepth m_modeDepth[NUM_CU_DEPTH]; | |
73 | bool m_bTryLossless; | |
74 | ||
75 | Analysis(); | |
76 | bool create(ThreadLocalData* tld); | |
77 | void destroy(); | |
78 | Search::Mode& compressCTU(CUData& ctu, Frame& frame, const CUGeom& cuGeom, const Entropy& initialContext); | |
79 | ||
80 | protected: | |
81 | ||
82 | /* mode analysis distribution */ | |
83 | int m_totalNumJobs; | |
84 | volatile int m_numAcquiredJobs; | |
85 | volatile int m_numCompletedJobs; | |
86 | Event m_modeCompletionEvent; | |
87 | bool findJob(int threadId); | |
88 | void parallelModeAnalysis(int threadId, int jobId); | |
89 | void parallelME(int threadId, int meId); | |
90 | ||
91 | /* full analysis for an I-slice CU */ | |
92 | void compressIntraCU(const CUData& parentCTU, const CUGeom& cuGeom, x265_intra_data* sdata, uint32_t &zOrder); | |
93 | ||
94 | /* full analysis for a P or B slice CU */ | |
95 | void compressInterCU_dist(const CUData& parentCTU, const CUGeom& cuGeom); | |
96 | void compressInterCU_rd0_4(const CUData& parentCTU, const CUGeom& cuGeom); | |
97 | void compressInterCU_rd5_6(const CUData& parentCTU, const CUGeom& cuGeom); | |
98 | ||
99 | /* measure merge and skip */ | |
100 | void checkMerge2Nx2N_rd0_4(Mode& skip, Mode& merge, const CUGeom& cuGeom); | |
101 | void checkMerge2Nx2N_rd5_6(Mode& skip, Mode& merge, const CUGeom& cuGeom); | |
102 | ||
103 | /* measure inter options */ | |
104 | void checkInter_rd0_4(Mode& interMode, const CUGeom& cuGeom, PartSize partSize); | |
105 | void checkInter_rd5_6(Mode& interMode, const CUGeom& cuGeom, PartSize partSize, bool bMergeOnly); | |
106 | ||
107 | /* measure intra options */ | |
108 | void checkIntraInInter_rd0_4(Mode& intraMode, const CUGeom& cuGeom); | |
109 | void encodeIntraInInter(Mode& intraMode, const CUGeom& cuGeom); | |
110 | ||
111 | /* encode current bestMode losslessly, pick best RD cost */ | |
112 | void tryLossless(const CUGeom& cuGeom); | |
113 | ||
114 | void checkDQP(CUData& cu, const CUGeom& cuGeom); | |
115 | void addSplitFlagCost(Mode& mode, uint32_t depth); | |
116 | void checkBestMode(Mode& mode, uint32_t depth); | |
117 | uint32_t topSkipMinDepth(const CUData& parentCTU, const CUGeom& cuGeom); | |
118 | bool recursionDepthCheck(const CUData& parentCTU, const CUGeom& cuGeom, const Mode& bestMode); | |
119 | ||
120 | void encodeResidue(const CUData& parentCTU, const CUGeom& cuGeom); | |
121 | }; | |
122 | ||
123 | struct ThreadLocalData | |
124 | { | |
125 | Analysis analysis; | |
126 | ||
127 | void destroy() { analysis.destroy(); } | |
128 | }; | |
129 | ||
130 | } | |
131 | ||
132 | #endif // ifndef X265_ANALYSIS_H |