39 |
* MinChen <chenm001@163.com> |
* MinChen <chenm001@163.com> |
40 |
* 14.04.2002 added FrameCodeB() |
* 14.04.2002 added FrameCodeB() |
41 |
* |
* |
42 |
* $Id: encoder.c,v 1.56 2002-07-18 23:52:40 chl Exp $ |
* $Id: encoder.c,v 1.61 2002-07-21 14:05:38 edgomez Exp $ |
43 |
* |
* |
44 |
****************************************************************************/ |
****************************************************************************/ |
45 |
|
|
209 |
|
|
210 |
/* 1 keyframe each 10 seconds */ |
/* 1 keyframe each 10 seconds */ |
211 |
|
|
212 |
if (pParam->max_key_interval == 0) |
if (pParam->max_key_interval <= 0) |
213 |
pParam->max_key_interval = 10 * pParam->fincr / pParam->fbase; |
pParam->max_key_interval = 10 * pParam->fincr / pParam->fbase; |
214 |
|
|
215 |
pEnc = (Encoder *) xvid_malloc(sizeof(Encoder), CACHE_LINE); |
pEnc = (Encoder *) xvid_malloc(sizeof(Encoder), CACHE_LINE); |
344 |
pEnc->global = pParam->global; |
pEnc->global = pParam->global; |
345 |
pEnc->mbParam.max_bframes = pParam->max_bframes; |
pEnc->mbParam.max_bframes = pParam->max_bframes; |
346 |
pEnc->bquant_ratio = pParam->bquant_ratio; |
pEnc->bquant_ratio = pParam->bquant_ratio; |
347 |
|
pEnc->frame_drop_ratio = pParam->frame_drop_ratio; |
348 |
pEnc->bframes = NULL; |
pEnc->bframes = NULL; |
349 |
|
|
350 |
if (pEnc->mbParam.max_bframes > 0) { |
if (pEnc->mbParam.max_bframes > 0) { |
422 |
pEnc->mbParam.m_seconds = 0; |
pEnc->mbParam.m_seconds = 0; |
423 |
pEnc->mbParam.m_ticks = 0; |
pEnc->mbParam.m_ticks = 0; |
424 |
pEnc->m_framenum = 0; |
pEnc->m_framenum = 0; |
425 |
|
pEnc->last_pframe = 1; |
426 |
#endif |
#endif |
427 |
|
|
428 |
pParam->handle = (void *) pEnc; |
pParam->handle = (void *) pEnc; |
1723 |
|
|
1724 |
pEnc->sStat.fMvPrevSigma = fSigma; |
pEnc->sStat.fMvPrevSigma = fSigma; |
1725 |
|
|
1726 |
|
#ifdef BFRAMES |
1727 |
|
/* frame drop code */ |
1728 |
|
// DPRINTF(DPRINTF_DEBUG, "kmu %i %i %i", pEnc->sStat.kblks, pEnc->sStat.mblks, pEnc->sStat.ublks); |
1729 |
|
if (pEnc->sStat.kblks + pEnc->sStat.mblks <= |
1730 |
|
(pEnc->frame_drop_ratio * pEnc->mbParam.mb_width * pEnc->mbParam.mb_height) / 100) |
1731 |
|
{ |
1732 |
|
pEnc->sStat.kblks = pEnc->sStat.mblks = 0; |
1733 |
|
pEnc->sStat.ublks = pEnc->mbParam.mb_width * pEnc->mbParam.mb_height; |
1734 |
|
|
1735 |
|
BitstreamReset(bs); |
1736 |
|
BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 0); |
1737 |
|
|
1738 |
|
// copy reference frame details into the current frame |
1739 |
|
pEnc->current->quant = pEnc->reference->quant; |
1740 |
|
pEnc->current->motion_flags = pEnc->reference->motion_flags; |
1741 |
|
pEnc->current->rounding_type = pEnc->reference->rounding_type; |
1742 |
|
pEnc->current->fcode = pEnc->reference->fcode; |
1743 |
|
pEnc->current->bcode = pEnc->reference->bcode; |
1744 |
|
image_copy(&pEnc->current->image, &pEnc->reference->image, pEnc->mbParam.edged_width, pEnc->mbParam.height); |
1745 |
|
memcpy(pEnc->current->mbs, pEnc->reference->mbs, sizeof(MACROBLOCK) * pEnc->mbParam.mb_width * pEnc->mbParam.mb_height); |
1746 |
|
|
1747 |
|
} |
1748 |
|
#endif |
1749 |
|
|
1750 |
*pBits = BitstreamPos(bs) - *pBits; |
*pBits = BitstreamPos(bs) - *pBits; |
1751 |
|
|
1752 |
|
#ifdef BFRAMES |
1753 |
|
pEnc->time_pp = ((int32_t)pEnc->mbParam.fbase - (int32_t)pEnc->last_pframe + (int32_t)pEnc->mbParam.m_ticks) % (int32_t)pEnc->mbParam.fbase; |
1754 |
|
|
1755 |
|
pEnc->last_pframe = pEnc->mbParam.m_ticks; |
1756 |
|
#endif |
1757 |
return 0; // inter |
return 0; // inter |
1758 |
} |
} |
1759 |
|
|
1809 |
stop_inter_timer(); |
stop_inter_timer(); |
1810 |
|
|
1811 |
start_timer(); |
start_timer(); |
1812 |
MotionEstimationBVOP(&pEnc->mbParam, frame, pEnc->reference->mbs, f_ref, |
MotionEstimationBVOP(&pEnc->mbParam, frame, |
1813 |
|
((int32_t)pEnc->mbParam.fbase + (int32_t)pEnc->mbParam.m_ticks + 1 - (int32_t)pEnc->last_pframe) % pEnc->mbParam.fbase, |
1814 |
|
pEnc->time_pp, |
1815 |
|
pEnc->reference->mbs, f_ref, |
1816 |
&pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv, |
&pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv, |
1817 |
pEnc->current->mbs, b_ref, &pEnc->vInterH, |
pEnc->current->mbs, b_ref, &pEnc->vInterH, |
1818 |
&pEnc->vInterV, &pEnc->vInterHV); |
&pEnc->vInterV, &pEnc->vInterHV); |