410 |
pEnc->queue_tail = 0; |
pEnc->queue_tail = 0; |
411 |
pEnc->queue_size = 0; |
pEnc->queue_size = 0; |
412 |
|
|
413 |
|
pEnc->mbParam.m_stamp = 0; |
414 |
|
|
|
pEnc->mbParam.m_seconds = 0; |
|
|
pEnc->mbParam.m_ticks = 0; |
|
415 |
pEnc->m_framenum = 0; |
pEnc->m_framenum = 0; |
416 |
pEnc->last_pframe = 0; |
pEnc->current->stamp = 0; |
417 |
pEnc->last_sync = 0; |
pEnc->reference->stamp = 0; |
418 |
|
|
419 |
pParam->handle = (void *) pEnc; |
pParam->handle = (void *) pEnc; |
420 |
|
|
603 |
|
|
604 |
static __inline void inc_frame_num(Encoder * pEnc) |
static __inline void inc_frame_num(Encoder * pEnc) |
605 |
{ |
{ |
606 |
pEnc->mbParam.m_ticks += pEnc->mbParam.fincr; |
pEnc->current->stamp = pEnc->mbParam.m_stamp; // first frame is zero |
607 |
|
pEnc->mbParam.m_stamp += pEnc->mbParam.fincr; |
|
pEnc->mbParam.m_ticks = pEnc->mbParam.m_ticks % pEnc->mbParam.fbase; |
|
|
if (pEnc->mbParam.m_ticks < pEnc->last_sync) |
|
|
pEnc->mbParam.m_seconds = 1; |
|
|
// more than 1 second since last I or P is not supported. |
|
|
else |
|
|
pEnc->mbParam.m_seconds = 0; |
|
|
|
|
608 |
} |
} |
609 |
|
|
610 |
|
|
633 |
pEnc->queue_tail = (pEnc->queue_tail + 1) % pEnc->mbParam.max_bframes; |
pEnc->queue_tail = (pEnc->queue_tail + 1) % pEnc->mbParam.max_bframes; |
634 |
} |
} |
635 |
|
|
636 |
|
static __inline void |
637 |
|
set_timecodes(FRAMEINFO* pCur,FRAMEINFO *pRef, int32_t time_base) |
638 |
|
{ |
639 |
|
|
640 |
|
pCur->ticks = (int32_t)pCur->stamp % time_base; |
641 |
|
pCur->seconds = ((int32_t)pCur->stamp / time_base) - ((int32_t)pRef->stamp / time_base) ; |
642 |
|
|
643 |
|
//HEAVY DEBUG OUTPUT remove when timecodes prove to be stable |
644 |
|
|
645 |
|
/* fprintf(stderr,"WriteVop: %d - %d \n", |
646 |
|
((int32_t)pCur->stamp / time_base), ((int32_t)pRef->stamp / time_base)); |
647 |
|
fprintf(stderr,"set_timecodes: VOP %1d stamp=%lld ref_stamp=%lld base=%d\n", |
648 |
|
pCur->coding_type, pCur->stamp, pRef->stamp, time_base); |
649 |
|
fprintf(stderr,"set_timecodes: VOP %1d seconds=%d ticks=%d (ref-sec=%d ref-tick=%d)\n", |
650 |
|
pCur->coding_type, pCur->seconds, pCur->ticks, pRef->seconds, pRef->ticks); |
651 |
|
|
652 |
|
*/ |
653 |
|
} |
654 |
|
|
655 |
|
|
656 |
|
|
657 |
|
|
658 |
|
|
659 |
/***************************************************************************** |
/***************************************************************************** |
672 |
{ |
{ |
673 |
uint16_t x, y; |
uint16_t x, y; |
674 |
Bitstream bs; |
Bitstream bs; |
675 |
uint32_t bits; |
uint32_t bits, mode; |
676 |
|
|
677 |
int input_valid = 1; |
int input_valid = 1; |
678 |
|
|
750 |
pEnc->bframenum_head, pEnc->bframenum_tail, |
pEnc->bframenum_head, pEnc->bframenum_tail, |
751 |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
752 |
|
|
753 |
|
set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase); |
754 |
BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0); |
BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0); |
755 |
BitstreamPad(&bs); |
BitstreamPad(&bs); |
756 |
BitstreamPutBits(&bs, 0x7f, 8); |
BitstreamPutBits(&bs, 0x7f, 8); |
823 |
|
|
824 |
pFrame->intra = 0; |
pFrame->intra = 0; |
825 |
|
|
826 |
|
set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase); |
827 |
BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0); // write N_VOP |
BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0); // write N_VOP |
828 |
BitstreamPad(&bs); |
BitstreamPad(&bs); |
829 |
pFrame->length = BitstreamLength(&bs); |
pFrame->length = BitstreamLength(&bs); |
861 |
pEnc->current->fcode = pEnc->mbParam.m_fcode; |
pEnc->current->fcode = pEnc->mbParam.m_fcode; |
862 |
pEnc->current->bcode = pEnc->mbParam.m_fcode; |
pEnc->current->bcode = pEnc->mbParam.m_fcode; |
863 |
|
|
|
pEnc->current->seconds = pEnc->mbParam.m_seconds; |
|
|
pEnc->current->ticks = pEnc->mbParam.m_ticks; |
|
|
|
|
864 |
inc_frame_num(pEnc); |
inc_frame_num(pEnc); |
865 |
|
|
866 |
#ifdef _DEBUG_PSNR |
#ifdef _DEBUG_PSNR |
919 |
if (pEnc->iFrameNum == 0 || pFrame->intra == 1 || pEnc->bframenum_dx50bvop >= 0 || |
if (pEnc->iFrameNum == 0 || pFrame->intra == 1 || pEnc->bframenum_dx50bvop >= 0 || |
920 |
(pFrame->intra < 0 && pEnc->iMaxKeyInterval > 0 && |
(pFrame->intra < 0 && pEnc->iMaxKeyInterval > 0 && |
921 |
pEnc->iFrameNum >= pEnc->iMaxKeyInterval) |
pEnc->iFrameNum >= pEnc->iMaxKeyInterval) |
922 |
|| image_mad(&pEnc->reference->image, &pEnc->current->image, |
|| /*image_mad(&pEnc->reference->image, &pEnc->current->image, |
923 |
pEnc->mbParam.edged_width, pEnc->mbParam.width, |
pEnc->mbParam.edged_width, pEnc->mbParam.width, |
924 |
pEnc->mbParam.height) > 30) { |
pEnc->mbParam.height) > 30) {*/ |
925 |
|
2 == (mode = MEanalysis(&pEnc->reference->image, &pEnc->current->image, |
926 |
|
&pEnc->mbParam, pEnc->current->mbs, pEnc->current->fcode))) { |
927 |
|
|
928 |
/* |
/* |
929 |
* This will be coded as an Intra Frame |
* This will be coded as an Intra Frame |
930 |
*/ |
*/ |
972 |
* NB : sequences like "IIBB" decode fine with msfdam but, |
* NB : sequences like "IIBB" decode fine with msfdam but, |
973 |
* go screwy with divx 5.00 |
* go screwy with divx 5.00 |
974 |
*/ |
*/ |
975 |
} else if (pEnc->bframenum_tail >= pEnc->mbParam.max_bframes) { |
} else if (pEnc->bframenum_tail >= pEnc->mbParam.max_bframes || mode != 0) { |
976 |
/* |
/* |
977 |
* This will be coded as a Predicted Frame |
* This will be coded as a Predicted Frame |
978 |
*/ |
*/ |
1067 |
pFrame->length, pFrame->intra); |
pFrame->length, pFrame->intra); |
1068 |
} |
} |
1069 |
|
|
|
|
|
1070 |
stop_global_timer(); |
stop_global_timer(); |
1071 |
write_timer(); |
write_timer(); |
1072 |
|
|
1110 |
|
|
1111 |
pEnc->current->global_flags = pFrame->general; |
pEnc->current->global_flags = pFrame->general; |
1112 |
pEnc->current->motion_flags = pFrame->motion; |
pEnc->current->motion_flags = pFrame->motion; |
|
pEnc->current->seconds = pEnc->mbParam.m_seconds; |
|
|
pEnc->current->ticks = pEnc->mbParam.m_ticks; |
|
1113 |
pEnc->mbParam.hint = &pFrame->hint; |
pEnc->mbParam.hint = &pFrame->hint; |
1114 |
|
|
1115 |
|
inc_frame_num(pEnc); |
1116 |
|
|
1117 |
/* disable alternate scan flag if interlacing is not enabled */ |
/* disable alternate scan flag if interlacing is not enabled */ |
1118 |
if ((pEnc->current->global_flags & XVID_ALTERNATESCAN) && |
if ((pEnc->current->global_flags & XVID_ALTERNATESCAN) && |
1119 |
!(pEnc->current->global_flags & XVID_INTERLACING)) |
!(pEnc->current->global_flags & XVID_INTERLACING)) |
1248 |
DEBUG(temp); |
DEBUG(temp); |
1249 |
#endif |
#endif |
1250 |
|
|
|
inc_frame_num(pEnc); |
|
1251 |
pEnc->iFrameNum++; |
pEnc->iFrameNum++; |
1252 |
|
|
1253 |
stop_global_timer(); |
stop_global_timer(); |
1504 |
if ((pEnc->global & XVID_GLOBAL_PACKED)) { |
if ((pEnc->global & XVID_GLOBAL_PACKED)) { |
1505 |
BitstreamWriteUserData(bs, DIVX501B481P, strlen(DIVX501B481P)); |
BitstreamWriteUserData(bs, DIVX501B481P, strlen(DIVX501B481P)); |
1506 |
} |
} |
1507 |
|
|
1508 |
|
set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase); |
1509 |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1); |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1); |
1510 |
|
|
1511 |
*pBits = BitstreamPos(bs); |
*pBits = BitstreamPos(bs); |
1546 |
pEnc->sStat.iMvCount = 0; |
pEnc->sStat.iMvCount = 0; |
1547 |
pEnc->mbParam.m_fcode = 2; |
pEnc->mbParam.m_fcode = 2; |
1548 |
|
|
|
pEnc->last_pframe = pEnc->current->ticks; |
|
|
pEnc->last_sync = pEnc->current->ticks; |
|
|
|
|
1549 |
if (pEnc->current->global_flags & XVID_HINTEDME_GET) { |
if (pEnc->current->global_flags & XVID_HINTEDME_GET) { |
1550 |
HintedMEGet(pEnc, 1); |
HintedMEGet(pEnc, 1); |
1551 |
} |
} |
1625 |
if (vol_header) |
if (vol_header) |
1626 |
BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current); |
BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current); |
1627 |
|
|
1628 |
|
|
1629 |
|
set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase); |
1630 |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1); |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1); |
1631 |
|
|
1632 |
*pBits = BitstreamPos(bs); |
*pBits = BitstreamPos(bs); |
1767 |
|
|
1768 |
pEnc->sStat.fMvPrevSigma = fSigma; |
pEnc->sStat.fMvPrevSigma = fSigma; |
1769 |
|
|
1770 |
#ifdef BFRAMES |
#ifdef FRAMEDROP |
1771 |
/* frame drop code */ |
/* frame drop code */ |
1772 |
// DPRINTF(DPRINTF_DEBUG, "kmu %i %i %i", pEnc->sStat.kblks, pEnc->sStat.mblks, pEnc->sStat.ublks); |
// DPRINTF(DPRINTF_DEBUG, "kmu %i %i %i", pEnc->sStat.kblks, pEnc->sStat.mblks, pEnc->sStat.ublks); |
1773 |
if (pEnc->sStat.kblks + pEnc->sStat.mblks < |
if (pEnc->sStat.kblks + pEnc->sStat.mblks < |
1777 |
pEnc->sStat.ublks = pEnc->mbParam.mb_width * pEnc->mbParam.mb_height; |
pEnc->sStat.ublks = pEnc->mbParam.mb_width * pEnc->mbParam.mb_height; |
1778 |
|
|
1779 |
BitstreamReset(bs); |
BitstreamReset(bs); |
1780 |
|
|
1781 |
|
set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase); |
1782 |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 0); |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 0); |
1783 |
|
|
1784 |
// copy reference frame details into the current frame |
// copy reference frame details into the current frame |
1795 |
|
|
1796 |
*pBits = BitstreamPos(bs) - *pBits; |
*pBits = BitstreamPos(bs) - *pBits; |
1797 |
|
|
|
pEnc->time_pp = ((int32_t)pEnc->mbParam.fbase - (int32_t)pEnc->last_pframe + (int32_t)pEnc->current->ticks) % |
|
|
(int32_t)pEnc->mbParam.fbase; |
|
|
pEnc->last_pframe = pEnc->current->ticks; |
|
|
|
|
1798 |
return 0; // inter |
return 0; // inter |
1799 |
} |
} |
1800 |
|
|
1845 |
stop_inter_timer(); |
stop_inter_timer(); |
1846 |
|
|
1847 |
start_timer(); |
start_timer(); |
1848 |
|
|
1849 |
MotionEstimationBVOP(&pEnc->mbParam, frame, |
MotionEstimationBVOP(&pEnc->mbParam, frame, |
1850 |
((int32_t)pEnc->mbParam.fbase + pEnc->last_pframe - frame->ticks) % pEnc->mbParam.fbase, |
((int32_t)(pEnc->current->stamp - frame->stamp)), // time_bp |
1851 |
pEnc->time_pp, |
((int32_t)(pEnc->current->stamp - pEnc->reference->stamp)), // time_pp |
1852 |
pEnc->reference->mbs, f_ref, |
pEnc->reference->mbs, f_ref, |
1853 |
&pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv, |
&pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv, |
1854 |
pEnc->current->mbs, b_ref, &pEnc->vInterH, |
pEnc->current->mbs, b_ref, &pEnc->vInterH, |
1863 |
} */ |
} */ |
1864 |
|
|
1865 |
frame->coding_type = B_VOP; |
frame->coding_type = B_VOP; |
1866 |
|
|
1867 |
|
set_timecodes(frame, pEnc->reference,pEnc->mbParam.fbase); |
1868 |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, frame, 1); |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, frame, 1); |
1869 |
|
|
1870 |
*pBits = BitstreamPos(bs); |
*pBits = BitstreamPos(bs); |