Fix cut&paste typo in changelog.
[deb_x265.git] / source / encoder / encoder.h
... / ...
CommitLineData
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
33struct x265_encoder {};
34
35namespace x265 {
36// private namespace
37extern const char g_sliceTypeToChar[3];
38
39class Entropy;
40
41struct 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
68class FrameEncoder;
69class DPB;
70class Lookahead;
71class RateControl;
72class ThreadPool;
73struct ThreadLocalData;
74
75class Encoder : public x265_encoder
76{
77public:
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 FILE* m_analysisFile;
117 int m_conformanceMode;
118 VPS m_vps;
119 SPS m_sps;
120 PPS m_pps;
121 NALList m_nalList;
122 ScalingList m_scalingList; // quantization matrix information
123 int m_numThreadLocalData;
124
125 int m_lastBPSEI;
126 uint32_t m_numDelayedPic;
127
128 x265_param* m_param;
129 RateControl* m_rateControl;
130 ThreadLocalData* m_threadLocalData;
131 Lookahead* m_lookahead;
132 Window m_conformanceWindow;
133
134 bool m_aborted; // fatal error detected
135
136 Encoder();
137 ~Encoder() {}
138
139 void create();
140 void destroy();
141
142 int encode(const x265_picture* pic, x265_picture *pic_out);
143
144 void getStreamHeaders(NALList& list, Entropy& sbacCoder, Bitstream& bs);
145
146 void fetchStats(x265_stats* stats, size_t statsSizeBytes);
147
148 void writeLog(int argc, char **argv);
149
150 void printSummary();
151
152 char* statsString(EncStats&, char*);
153
154 char* statsCSVString(EncStats& stat, char* buffer);
155
156 void setThreadPool(ThreadPool* p) { m_threadPool = p; }
157
158 void configure(x265_param *param);
159
160 void updateVbvPlan(RateControl* rc);
161
162 void allocAnalysis(x265_analysis_data* analysis);
163
164 void freeAnalysis(x265_analysis_data* analysis);
165
166 void readAnalysisFile(x265_analysis_data* analysis, int poc);
167
168 void writeAnalysisFile(x265_analysis_data* pic);
169
170 void finishFrameStats(Frame* pic, FrameEncoder *curEncoder, uint64_t bits);
171
172protected:
173
174 void initSPS(SPS *sps);
175 void initPPS(PPS *pps);
176};
177}
178
179#endif // ifndef X265_ENCODER_H