--- encoder.c 2004/03/22 22:36:23 1.102 +++ encoder.c 2004/03/30 12:31:52 1.103 @@ -21,7 +21,7 @@ * along with this program ; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: encoder.c,v 1.102 2004/03/22 22:36:23 edgomez Exp $ + * $Id: encoder.c,v 1.103 2004/03/30 12:31:52 syskin Exp $ * ****************************************************************************/ @@ -123,6 +123,9 @@ if (create->width%2 || create->height%2) return XVID_ERR_FAIL; + if (create->width<=0 || create->height<=0) + return XVID_ERR_FAIL; + /* allocate encoder struct */ pEnc = (Encoder *) xvid_malloc(sizeof(Encoder), CACHE_LINE); @@ -1086,6 +1089,7 @@ DPRINTF(XVID_DEBUG_DEBUG,"*** PFRAME bf: head=%i tail=%i queue: head=%i tail=%i size=%i\n", pEnc->bframenum_head, pEnc->bframenum_tail, pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); + pEnc->mbParam.frame_drop_ratio = -1; /* it must be a coded vop */ FrameCodeP(pEnc, &bs, 1, 0); @@ -1339,7 +1343,11 @@ pEnc->mbParam.edged_width, pEnc->mbParam.height); } - FrameCodeP(pEnc, &bs, 1, 0); + if ( FrameCodeP(pEnc, &bs, 1, 0) == 0 ) { + /* N-VOP, we mustn't code b-frames yet */ + call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats); + goto done; + } } @@ -1536,6 +1544,7 @@ MBParam * const pParam = &pEnc->mbParam; int mb_width = pParam->mb_width; int mb_height = pParam->mb_height; + int coded = 1; /* IMAGE *pCurrent = ¤t->image; */ @@ -1863,7 +1872,7 @@ #if 0 DPRINTF(XVID_DEBUG_DEBUG, "kmu %i %i %i\n", current->sStat.kblks, current->sStat.mblks, current->sStat.ublks); #endif - if (current->sStat.kblks + current->sStat.mblks < + if (current->sStat.kblks + current->sStat.mblks <= (pParam->frame_drop_ratio * mb_width * mb_height) / 100) { current->sStat.kblks = current->sStat.mblks = 0; @@ -1880,20 +1889,23 @@ current->rounding_type = reference->rounding_type; current->fcode = reference->fcode; current->bcode = reference->bcode; + current->stamp = reference->stamp; image_copy(¤t->image, &reference->image, pParam->edged_width, pParam->height); memcpy(current->mbs, reference->mbs, sizeof(MACROBLOCK) * mb_width * mb_height); - } - - pEnc->current->is_edged = 0; /* not edged */ - pEnc->current->is_interpolated = -1; /* not interpolated (fake rounding -1) */ + coded = 0; + + } else { - /* what was this frame's interpolated reference will become - forward (past) reference in b-frame coding */ + pEnc->current->is_edged = 0; /* not edged */ + pEnc->current->is_interpolated = -1; /* not interpolated (fake rounding -1) */ - image_swap(&pEnc->vInterH, &pEnc->f_refh); - image_swap(&pEnc->vInterV, &pEnc->f_refv); - image_swap(&pEnc->vInterHV, &pEnc->f_refhv); + /* what was this frame's interpolated reference will become + forward (past) reference in b-frame coding */ + image_swap(&pEnc->vInterH, &pEnc->f_refh); + image_swap(&pEnc->vInterV, &pEnc->f_refv); + image_swap(&pEnc->vInterHV, &pEnc->f_refhv); + } /* XXX: debug { @@ -1914,7 +1926,7 @@ current->length = (BitstreamPos(bs) - bits) / 8; - return 0; /* inter */ + return coded; }