Commit | Line | Data |
---|---|---|
72b9787e JB |
1 | /***************************************************************************** |
2 | * Copyright (C) 2013 x265 project | |
3 | * | |
4 | * Authors: Steve Borho <steve@borho.org> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. | |
19 | * | |
20 | * This program is also available under a commercial proprietary license. | |
21 | * For more information, contact us at license @ x265.com. | |
22 | *****************************************************************************/ | |
23 | ||
24 | #ifndef X265_ENCODER_H | |
25 | #define X265_ENCODER_H | |
26 | ||
27 | #include "common.h" | |
28 | #include "slice.h" | |
29 | #include "scalinglist.h" | |
30 | #include "x265.h" | |
31 | #include "nal.h" | |
32 | ||
33 | struct x265_encoder {}; | |
34 | ||
35 | namespace x265 { | |
36 | // private namespace | |
37 | extern const char g_sliceTypeToChar[3]; | |
38 | ||
39 | class Entropy; | |
40 | ||
41 | struct EncStats | |
42 | { | |
43 | double m_psnrSumY; | |
44 | double m_psnrSumU; | |
45 | double m_psnrSumV; | |
46 | double m_globalSsim; | |
47 | double m_totalQp; | |
48 | uint64_t m_accBits; | |
49 | uint32_t m_numPics; | |
50 | ||
51 | EncStats() | |
52 | { | |
53 | m_psnrSumY = m_psnrSumU = m_psnrSumV = m_globalSsim = 0; | |
54 | m_accBits = 0; | |
55 | m_numPics = 0; | |
56 | m_totalQp = 0; | |
57 | } | |
58 | ||
59 | void addQP(double aveQp); | |
60 | ||
61 | void addPsnr(double psnrY, double psnrU, double psnrV); | |
62 | ||
63 | void addBits(uint64_t bits); | |
64 | ||
65 | void addSsim(double ssim); | |
66 | }; | |
67 | ||
68 | class FrameEncoder; | |
69 | class DPB; | |
70 | class Lookahead; | |
71 | class RateControl; | |
72 | class ThreadPool; | |
73 | struct ThreadLocalData; | |
74 | ||
75 | class Encoder : public x265_encoder | |
76 | { | |
77 | private: | |
78 | ||
79 | int m_pocLast; // time index (POC) | |
80 | int m_encodedFrameNum; | |
81 | int m_outputCount; | |
82 | ||
83 | int m_bframeDelay; | |
84 | int64_t m_firstPts; | |
85 | int64_t m_bframeDelayTime; | |
86 | int64_t m_prevReorderedPts[2]; | |
87 | ||
88 | ThreadPool* m_threadPool; | |
89 | FrameEncoder* m_frameEncoder; | |
90 | DPB* m_dpb; | |
91 | ||
92 | Frame* m_exportedPic; | |
93 | ||
94 | int m_curEncoder; | |
95 | ||
96 | /* cached PicYuv offset arrays, shared by all instances of | |
97 | * PicYuv created by this encoder */ | |
98 | intptr_t* m_cuOffsetY; | |
99 | intptr_t* m_cuOffsetC; | |
100 | intptr_t* m_buOffsetY; | |
101 | intptr_t* m_buOffsetC; | |
102 | ||
103 | /* Collect statistics globally */ | |
104 | EncStats m_analyzeAll; | |
105 | EncStats m_analyzeI; | |
106 | EncStats m_analyzeP; | |
107 | EncStats m_analyzeB; | |
108 | FILE* m_csvfpt; | |
109 | int64_t m_encodeStartTime; | |
110 | ||
111 | // weighted prediction | |
112 | int m_numLumaWPFrames; // number of P frames with weighted luma reference | |
113 | int m_numChromaWPFrames; // number of P frames with weighted chroma reference | |
114 | int m_numLumaWPBiFrames; // number of B frames with weighted luma reference | |
115 | int m_numChromaWPBiFrames; // number of B frames with weighted chroma reference | |
116 | ||
117 | public: | |
118 | ||
119 | int m_conformanceMode; | |
120 | VPS m_vps; | |
121 | SPS m_sps; | |
122 | PPS m_pps; | |
123 | NALList m_nalList; | |
124 | ScalingList m_scalingList; // quantization matrix information | |
125 | int m_numThreadLocalData; | |
126 | ||
127 | int m_lastBPSEI; | |
128 | uint32_t m_numDelayedPic; | |
129 | ||
130 | x265_param* m_param; | |
131 | RateControl* m_rateControl; | |
132 | ThreadLocalData* m_threadLocalData; | |
133 | Lookahead* m_lookahead; | |
134 | Window m_conformanceWindow; | |
135 | ||
136 | bool m_aborted; // fatal error detected | |
137 | ||
138 | Encoder(); | |
139 | ||
140 | ~Encoder() {} | |
141 | ||
142 | void create(); | |
143 | void destroy(); | |
144 | void init(); | |
145 | ||
146 | int encode(const x265_picture* pic, x265_picture *pic_out); | |
147 | ||
148 | void getStreamHeaders(NALList& list, Entropy& sbacCoder, Bitstream& bs); | |
149 | ||
150 | void fetchStats(x265_stats* stats, size_t statsSizeBytes); | |
151 | ||
152 | void writeLog(int argc, char **argv); | |
153 | ||
154 | void printSummary(); | |
155 | ||
156 | char* statsString(EncStats&, char*); | |
157 | ||
158 | char* statsCSVString(EncStats& stat, char* buffer); | |
159 | ||
160 | void setThreadPool(ThreadPool* p) { m_threadPool = p; } | |
161 | ||
162 | void configure(x265_param *param); | |
163 | ||
164 | void updateVbvPlan(RateControl* rc); | |
165 | ||
166 | protected: | |
167 | ||
168 | void initSPS(SPS *sps); | |
169 | void initPPS(PPS *pps); | |
170 | ||
171 | void finishFrameStats(Frame* pic, FrameEncoder *curEncoder, uint64_t bits); | |
172 | }; | |
173 | } | |
174 | ||
175 | #endif // ifndef X265_ENCODER_H |