1 /*****************************************************************************
2 * Copyright (C) 2013 x265 project
4 * Authors: Steve Borho <steve@borho.org>
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.
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.
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.
20 * This program is also available under a commercial proprietary license.
21 * For more information, contact us at license @ x265.com.
22 *****************************************************************************/
24 #ifndef X265_ENCODER_H
25 #define X265_ENCODER_H
29 #include "scalinglist.h"
33 struct x265_encoder
{};
37 extern const char g_sliceTypeToChar
[3];
53 m_psnrSumY
= m_psnrSumU
= m_psnrSumV
= m_globalSsim
= 0;
59 void addQP(double aveQp
);
61 void addPsnr(double psnrY
, double psnrU
, double psnrV
);
63 void addBits(uint64_t bits
);
65 void addSsim(double ssim
);
73 struct ThreadLocalData
;
75 class Encoder
: public x265_encoder
79 int m_pocLast
; // time index (POC)
80 int m_encodedFrameNum
;
85 int64_t m_bframeDelayTime
;
86 int64_t m_prevReorderedPts
[2];
88 ThreadPool
* m_threadPool
;
89 FrameEncoder
* m_frameEncoder
;
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
;
103 /* Collect statistics globally */
104 EncStats m_analyzeAll
;
109 int64_t m_encodeStartTime
;
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
119 int m_conformanceMode
;
124 ScalingList m_scalingList
; // quantization matrix information
125 int m_numThreadLocalData
;
128 uint32_t m_numDelayedPic
;
131 RateControl
* m_rateControl
;
132 ThreadLocalData
* m_threadLocalData
;
133 Lookahead
* m_lookahead
;
134 Window m_conformanceWindow
;
136 bool m_aborted
; // fatal error detected
146 int encode(const x265_picture
* pic
, x265_picture
*pic_out
);
148 void getStreamHeaders(NALList
& list
, Entropy
& sbacCoder
, Bitstream
& bs
);
150 void fetchStats(x265_stats
* stats
, size_t statsSizeBytes
);
152 void writeLog(int argc
, char **argv
);
156 char* statsString(EncStats
&, char*);
158 char* statsCSVString(EncStats
& stat
, char* buffer
);
160 void setThreadPool(ThreadPool
* p
) { m_threadPool
= p
; }
162 void configure(x265_param
*param
);
164 void updateVbvPlan(RateControl
* rc
);
168 void initSPS(SPS
*sps
);
169 void initPPS(PPS
*pps
);
171 void finishFrameStats(Frame
* pic
, FrameEncoder
*curEncoder
, uint64_t bits
);
175 #endif // ifndef X265_ENCODER_H