15 |
#include "utils/emms.h" |
#include "utils/emms.h" |
16 |
#include "bitstream/mbcoding.h" |
#include "bitstream/mbcoding.h" |
17 |
#include "quant/adapt_quant.h" |
#include "quant/adapt_quant.h" |
18 |
|
#include "quant/quant_matrix.h" |
19 |
|
|
20 |
#define ENC_CHECK(X) if(!(X)) return XVID_ERR_FORMAT |
#define ENC_CHECK(X) if(!(X)) return XVID_ERR_FORMAT |
21 |
|
|
187 |
} |
} |
188 |
|
|
189 |
create_vlc_tables(); |
create_vlc_tables(); |
190 |
|
init_timer(); |
191 |
|
|
192 |
return XVID_ERR_OK; |
return XVID_ERR_OK; |
193 |
} |
} |
217 |
uint16_t x, y; |
uint16_t x, y; |
218 |
Bitstream bs; |
Bitstream bs; |
219 |
uint32_t bits; |
uint32_t bits; |
220 |
uint16_t quant_type = 0; |
uint16_t write_vol_header = 0; |
|
uint16_t quant_change = 0; |
|
|
|
|
|
IMAGE *pCurrent = &(pEnc->sCurrent); |
|
221 |
|
|
222 |
start_global_timer(); |
start_global_timer(); |
223 |
|
|
265 |
free(temp_dquants); |
free(temp_dquants); |
266 |
} |
} |
267 |
|
|
268 |
if(pEnc->mbParam.global_flags & XVID_H263QUANT) |
if(pEnc->mbParam.global_flags & XVID_H263QUANT) { |
269 |
quant_type = H263_QUANT; |
if(pEnc->mbParam.quant_type != H263_QUANT) |
270 |
else if(pEnc->mbParam.global_flags & XVID_MPEGQUANT) |
write_vol_header = 1; |
271 |
quant_type = MPEG4_QUANT; |
pEnc->mbParam.quant_type = H263_QUANT; |
272 |
|
} |
273 |
if(pEnc->mbParam.quant_type != quant_type) { |
else if(pEnc->mbParam.global_flags & XVID_MPEGQUANT) { |
274 |
pEnc->mbParam.quant_type = quant_type; |
int ret1, ret2; |
275 |
quant_change = 1; |
|
276 |
|
if(pEnc->mbParam.quant_type != MPEG4_QUANT) |
277 |
|
write_vol_header = 1; |
278 |
|
|
279 |
|
pEnc->mbParam.quant_type = MPEG4_QUANT; |
280 |
|
|
281 |
|
if ((pEnc->mbParam.global_flags & XVID_CUSTOM_QMATRIX) > 0) { |
282 |
|
if(pFrame->quant_intra_matrix != NULL) |
283 |
|
ret1 = set_intra_matrix(pFrame->quant_intra_matrix); |
284 |
|
if(pFrame->quant_inter_matrix != NULL) |
285 |
|
ret2 = set_inter_matrix(pFrame->quant_inter_matrix); |
286 |
|
} |
287 |
|
else { |
288 |
|
ret1 = set_intra_matrix(get_default_intra_matrix()); |
289 |
|
ret2 = set_inter_matrix(get_default_inter_matrix()); |
290 |
|
} |
291 |
|
if(write_vol_header == 0) |
292 |
|
write_vol_header = ret1 | ret2; |
293 |
} |
} |
|
else |
|
|
quant_change = 0; |
|
|
|
|
294 |
|
|
295 |
if (pFrame->intra < 0) |
if (pFrame->intra < 0) |
296 |
{ |
{ |
299 |
|
|
300 |
pFrame->intra = FrameCodeI(pEnc, &bs, &bits); |
pFrame->intra = FrameCodeI(pEnc, &bs, &bits); |
301 |
else |
else |
302 |
pFrame->intra = FrameCodeP(pEnc, &bs, &bits, 0, quant_change); |
pFrame->intra = FrameCodeP(pEnc, &bs, &bits, 0, write_vol_header); |
303 |
} |
} |
304 |
else |
else |
305 |
{ |
{ |
306 |
if (pFrame->intra == 1) |
if (pFrame->intra == 1) |
307 |
pFrame->intra = FrameCodeI(pEnc, &bs, &bits); |
pFrame->intra = FrameCodeI(pEnc, &bs, &bits); |
308 |
else |
else |
309 |
pFrame->intra = FrameCodeP(pEnc, &bs, &bits, 1, quant_change); |
pFrame->intra = FrameCodeP(pEnc, &bs, &bits, 1, write_vol_header); |
310 |
} |
} |
311 |
|
|
312 |
BitstreamPutBits(&bs, 0xFFFF, 16); |
BitstreamPutBits(&bs, 0xFFFF, 16); |
323 |
pResult->ublks = pEnc->sStat.ublks; |
pResult->ublks = pEnc->sStat.ublks; |
324 |
} |
} |
325 |
|
|
326 |
if (pEnc->bitrate) |
if (pFrame->quant == 0) |
327 |
{ |
{ |
328 |
RateControlUpdate(pEnc->mbParam.quant, pFrame->length, pFrame->intra); |
RateControlUpdate(pEnc->mbParam.quant, pFrame->length, pFrame->intra); |
329 |
} |
} |
362 |
int16_t dct_codes[6][64]; |
int16_t dct_codes[6][64]; |
363 |
int16_t qcoeff[6][64]; |
int16_t qcoeff[6][64]; |
364 |
uint16_t x, y; |
uint16_t x, y; |
|
IMAGE *pCurrent = &pEnc->sCurrent; |
|
365 |
|
|
366 |
pEnc->iFrameNum = 0; |
pEnc->iFrameNum = 0; |
367 |
pEnc->mbParam.rounding_type = 1; |
pEnc->mbParam.rounding_type = 1; |
385 |
|
|
386 |
CodeIntraMB(pEnc, pMB); |
CodeIntraMB(pEnc, pMB); |
387 |
|
|
388 |
MBTransQuantIntra(&pEnc->mbParam, x, y, dct_codes, qcoeff, pCurrent); |
MBTransQuantIntra(&pEnc->mbParam, x, y, dct_codes, qcoeff, &pEnc->sCurrent); |
389 |
|
|
390 |
start_timer(); |
start_timer(); |
391 |
MBPrediction(&pEnc->mbParam, x, y, pEnc->mbParam.mb_width, qcoeff, pEnc->pMBs); |
MBPrediction(&pEnc->mbParam, x, y, pEnc->mbParam.mb_width, qcoeff, pEnc->pMBs); |