1 |
/************************************************************************** |
/***************************************************************************** |
2 |
* |
* |
3 |
* Modifications: |
* XVID MPEG-4 VIDEO CODEC |
4 |
|
* - Encoder header - |
5 |
* |
* |
6 |
* 22.08.2001 added support for EXT_MODE encoding mode |
* Copyright(C) 2002 Michael Militzer |
|
* support for EXTENDED API |
|
|
* 22.08.2001 fixed bug in iDQtab |
|
7 |
* |
* |
8 |
* Michael Militzer <isibaar@videocoding.de> |
* This program is an implementation of a part of one or more MPEG-4 |
9 |
|
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
10 |
|
* to use this software module in hardware or software products are |
11 |
|
* advised that its use may infringe existing patents or copyrights, and |
12 |
|
* any such use would be at such party's own risk. The original |
13 |
|
* developer of this software module and his/her company, and subsequent |
14 |
|
* editors and their companies, will have no liability for use of this |
15 |
|
* software or modifications or derivatives thereof. |
16 |
* |
* |
17 |
**************************************************************************/ |
* This program is free software ; you can redistribute it and/or modify |
18 |
|
* it under the terms of the GNU General Public License as published by |
19 |
|
* the Free Software Foundation ; either version 2 of the License, or |
20 |
|
* (at your option) any later version. |
21 |
|
* |
22 |
|
* This program is distributed in the hope that it will be useful, |
23 |
|
* but WITHOUT ANY WARRANTY ; without even the implied warranty of |
24 |
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
25 |
|
* GNU General Public License for more details. |
26 |
|
* |
27 |
|
* You should have received a copy of the GNU General Public License |
28 |
|
* along with this program ; if not, write to the Free Software |
29 |
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
30 |
|
* |
31 |
|
****************************************************************************/ |
32 |
|
|
33 |
#ifndef _ENCODER_H_ |
#ifndef _ENCODER_H_ |
34 |
#define _ENCODER_H_ |
#define _ENCODER_H_ |
35 |
|
|
|
|
|
36 |
#include "xvid.h" |
#include "xvid.h" |
|
|
|
37 |
#include "portab.h" |
#include "portab.h" |
38 |
#include "global.h" |
#include "global.h" |
39 |
#include "image/image.h" |
#include "image/image.h" |
40 |
|
#include "utils/ratecontrol.h" |
41 |
|
|
42 |
|
/***************************************************************************** |
43 |
|
* Constants |
44 |
|
****************************************************************************/ |
45 |
|
|
46 |
|
/* Quatization type */ |
47 |
#define H263_QUANT 0 |
#define H263_QUANT 0 |
48 |
#define MPEG4_QUANT 1 |
#define MPEG4_QUANT 1 |
49 |
|
|
50 |
|
/* Indicates no quantizer changes in INTRA_Q/INTER_Q modes */ |
51 |
|
#define NO_CHANGE 64 |
52 |
|
|
53 |
typedef uint32_t bool; |
/***************************************************************************** |
54 |
|
* Types |
55 |
|
****************************************************************************/ |
56 |
|
|
57 |
|
typedef int bool; |
58 |
|
|
59 |
typedef enum |
typedef enum |
60 |
{ |
{ |
61 |
I_VOP = 0, |
I_VOP = 0, |
62 |
P_VOP = 1 |
P_VOP = 1, |
63 |
|
B_VOP = 2 |
64 |
} |
} |
65 |
VOP_TYPE; |
VOP_TYPE; |
66 |
|
|
67 |
/*********************************** |
/***************************************************************************** |
68 |
|
* Structures |
69 |
Encoding Parameters |
****************************************************************************/ |
|
|
|
|
************************************/ |
|
70 |
|
|
71 |
typedef struct |
typedef struct |
72 |
{ |
{ |
78 |
uint32_t mb_width; |
uint32_t mb_width; |
79 |
uint32_t mb_height; |
uint32_t mb_height; |
80 |
|
|
81 |
VOP_TYPE coding_type; |
/* frame rate increment & base */ |
82 |
|
uint32_t fincr; |
83 |
|
uint32_t fbase; |
84 |
|
|
85 |
|
#ifdef _SMP |
86 |
|
int num_threads; |
87 |
|
#endif |
88 |
|
|
89 |
/* rounding type; alternate 0-1 after each interframe */ |
/* rounding type; alternate 0-1 after each interframe */ |
|
|
|
|
uint32_t rounding_type; |
|
|
|
|
90 |
/* 1 <= fixed_code <= 4 |
/* 1 <= fixed_code <= 4 |
91 |
automatically adjusted using motion vector statistics inside |
automatically adjusted using motion vector statistics inside |
92 |
*/ |
*/ |
93 |
|
|
94 |
uint32_t fixed_code; |
/* vars that not "quite" frame independant */ |
95 |
|
uint32_t m_quant_type; |
96 |
|
uint32_t m_rounding_type; |
97 |
|
uint32_t m_fcode; |
98 |
|
|
99 |
|
HINTINFO *hint; |
100 |
|
|
101 |
|
uint32_t m_seconds; |
102 |
|
uint32_t m_ticks; |
103 |
|
|
104 |
|
} |
105 |
|
MBParam; |
106 |
|
|
107 |
|
|
108 |
|
typedef struct |
109 |
|
{ |
110 |
uint32_t quant; |
uint32_t quant; |
|
uint32_t quant_type; |
|
111 |
uint32_t motion_flags; |
uint32_t motion_flags; |
112 |
uint32_t global_flags; |
uint32_t global_flags; |
113 |
} MBParam; |
|
114 |
|
VOP_TYPE coding_type; |
115 |
|
uint32_t rounding_type; |
116 |
|
uint32_t fcode; |
117 |
|
uint32_t bcode; |
118 |
|
|
119 |
|
uint32_t seconds; |
120 |
|
uint32_t ticks; |
121 |
|
|
122 |
|
IMAGE image; |
123 |
|
|
124 |
|
MACROBLOCK *mbs; |
125 |
|
|
126 |
|
} |
127 |
|
FRAMEINFO; |
128 |
|
|
129 |
typedef struct |
typedef struct |
130 |
{ |
{ |
146 |
|
|
147 |
int iFrameNum; |
int iFrameNum; |
148 |
int iMaxKeyInterval; |
int iMaxKeyInterval; |
|
int lum_masking; |
|
149 |
int bitrate; |
int bitrate; |
150 |
|
|
151 |
// images |
// images |
152 |
|
|
153 |
IMAGE sCurrent; |
FRAMEINFO *current; |
154 |
IMAGE sReference; |
FRAMEINFO *reference; |
155 |
|
|
156 |
|
#ifdef _DEBUG_PSNR |
157 |
|
IMAGE sOriginal; |
158 |
|
#endif |
159 |
IMAGE vInterH; |
IMAGE vInterH; |
160 |
IMAGE vInterV; |
IMAGE vInterV; |
161 |
|
IMAGE vInterVf; |
162 |
IMAGE vInterHV; |
IMAGE vInterHV; |
163 |
|
IMAGE vInterHVf; |
|
// macroblock |
|
|
|
|
|
MACROBLOCK * pMBs; |
|
164 |
|
|
165 |
Statistics sStat; |
Statistics sStat; |
166 |
|
RateControl rate_control; |
167 |
} |
} |
168 |
Encoder; |
Encoder; |
169 |
|
|
170 |
|
/***************************************************************************** |
171 |
|
* Inline functions |
172 |
|
****************************************************************************/ |
173 |
|
|
174 |
// indicates no quantizer changes in INTRA_Q/INTER_Q modes |
static __inline uint8_t |
175 |
#define NO_CHANGE 64 |
get_fcode(uint16_t sr) |
|
|
|
|
void init_encoder(uint32_t cpu_flags); |
|
|
|
|
|
int encoder_create(XVID_ENC_PARAM * pParam); |
|
|
int encoder_destroy(Encoder * pEnc); |
|
|
int encoder_encode(Encoder * pEnc, XVID_ENC_FRAME * pFrame, XVID_ENC_STATS * pResult); |
|
|
|
|
|
static __inline uint8_t get_fcode(uint16_t sr) |
|
176 |
{ |
{ |
177 |
if (sr <= 16) |
if (sr <= 16) |
178 |
return 1; |
return 1; |
199 |
return 0; |
return 0; |
200 |
} |
} |
201 |
|
|
202 |
#endif /* _ENCODER_H_ */ |
|
203 |
|
/***************************************************************************** |
204 |
|
* Prototypes |
205 |
|
****************************************************************************/ |
206 |
|
|
207 |
|
void init_encoder(uint32_t cpu_flags); |
208 |
|
|
209 |
|
int encoder_create(XVID_ENC_PARAM * pParam); |
210 |
|
int encoder_destroy(Encoder * pEnc); |
211 |
|
int encoder_encode(Encoder * pEnc, |
212 |
|
XVID_ENC_FRAME * pFrame, |
213 |
|
XVID_ENC_STATS * pResult); |
214 |
|
|
215 |
|
int encoder_encode_bframes(Encoder * pEnc, |
216 |
|
XVID_ENC_FRAME * pFrame, |
217 |
|
XVID_ENC_STATS * pResult); |
218 |
|
|
219 |
|
#endif |