--- branches/dev-api-3/xvidcore/src/encoder.c 2002/09/29 15:53:42 569 +++ branches/dev-api-3/xvidcore/src/encoder.c 2002/10/02 12:57:25 575 @@ -39,7 +39,7 @@ * MinChen * 14.04.2002 added FrameCodeB() * - * $Id: encoder.c,v 1.76.2.5 2002-09-29 15:53:42 chl Exp $ + * $Id: encoder.c,v 1.76.2.9 2002-10-02 12:57:25 suxen_drol Exp $ * ****************************************************************************/ @@ -411,8 +411,10 @@ pEnc->queue_size = 0; pEnc->mbParam.m_stamp = 0; -; + pEnc->m_framenum = 0; + pEnc->current->stamp = 0; + pEnc->reference->stamp = 0; pParam->handle = (void *) pEnc; @@ -640,14 +642,14 @@ //HEAVY DEBUG OUTPUT remove when timecodes prove to be stable - fprintf(stderr,"WriteVop: %d - %d \n", +/* fprintf(stderr,"WriteVop: %d - %d \n", ((int32_t)pCur->stamp / time_base), ((int32_t)pRef->stamp / time_base)); fprintf(stderr,"set_timecodes: VOP %1d stamp=%lld ref_stamp=%lld base=%d\n", pCur->coding_type, pCur->stamp, pRef->stamp, time_base); fprintf(stderr,"set_timecodes: VOP %1d seconds=%d ticks=%d (ref-sec=%d ref-tick=%d)\n", pCur->coding_type, pCur->seconds, pCur->ticks, pRef->seconds, pRef->ticks); - +*/ } @@ -742,16 +744,26 @@ if (pEnc->bframenum_head > 0) { pEnc->bframenum_head = pEnc->bframenum_tail = 0; + /* write an empty marker to the bitstream. + + for divx5 decoder compatibility, this marker must consist + of a not-coded p-vop, with a time_base of zero, and time_increment + indentical to the future-referece frame. + */ + if ((pEnc->global & XVID_GLOBAL_PACKED)) { + int tmp; DPRINTF(DPRINTF_DEBUG,"*** EMPTY bf: head=%i tail=%i queue: head=%i tail=%i size=%i", pEnc->bframenum_head, pEnc->bframenum_tail, pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); - set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase); - BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0); BitstreamPad(&bs); - BitstreamPutBits(&bs, 0x7f, 8); + + tmp = pEnc->current->seconds; + pEnc->current->seconds = 0; /* force time_base = 0 */ + BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0); + pEnc->current->seconds = tmp; pFrame->length = BitstreamLength(&bs); pFrame->intra = 0; @@ -813,22 +825,20 @@ pEnc->queue_head = (pEnc->queue_head + 1) % pEnc->mbParam.max_bframes; pEnc->queue_size--; - } else if (BitstreamPos(&bs) == 0) { + } else { - DPRINTF(DPRINTF_DEBUG,"*** SKIP bf: head=%i tail=%i queue: head=%i tail=%i size=%i", - pEnc->bframenum_head, pEnc->bframenum_tail, - pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); + /* if nothing was encoded, write an 'ignore this frame' flag + to the bitstream */ - pFrame->intra = 0; + if (BitstreamPos(&bs) == 0) { - set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase); - BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0); // write N_VOP - BitstreamPad(&bs); - pFrame->length = BitstreamLength(&bs); - - return XVID_ERR_OK; + DPRINTF(DPRINTF_DEBUG,"*** SKIP bf: head=%i tail=%i queue: head=%i tail=%i size=%i", + pEnc->bframenum_head, pEnc->bframenum_tail, + pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); - } else { + BitstreamPutBits(&bs, 0x7f, 8); + pFrame->intra = 0; + } pFrame->length = BitstreamLength(&bs); return XVID_ERR_OK; @@ -1110,6 +1120,8 @@ pEnc->current->motion_flags = pFrame->motion; pEnc->mbParam.hint = &pFrame->hint; + inc_frame_num(pEnc); + /* disable alternate scan flag if interlacing is not enabled */ if ((pEnc->current->global_flags & XVID_ALTERNATESCAN) && !(pEnc->current->global_flags & XVID_INTERLACING)) @@ -1244,7 +1256,6 @@ DEBUG(temp); #endif - inc_frame_num(pEnc); pEnc->iFrameNum++; stop_global_timer();