[cvs] / xvidcore / src / encoder.c Repository:
ViewVC logotype

Diff of /xvidcore/src/encoder.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.14, Fri Mar 29 04:25:15 2002 UTC revision 1.22, Sun Apr 7 11:57:47 2002 UTC
# Line 166  Line 166 
166    
167          if (pParam->bitrate)          if (pParam->bitrate)
168          {          {
169                  RateControlInit(pParam->bitrate, pParam->rc_buffersize, pParam->fbase * 100 / pParam->fincr,                  RateControlInit(pParam->bitrate, pParam->rc_buffersize, pParam->fbase * 1000 / pParam->fincr,
170                                  pParam->max_quantizer, pParam->min_quantizer);                                  pParam->max_quantizer, pParam->min_quantizer);
171          }          }
172    
         create_vlc_tables();  
173          init_timer();          init_timer();
174    
175          return XVID_ERR_OK;          return XVID_ERR_OK;
# Line 188  Line 187 
187          image_destroy(&pEnc->sReference, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height);          image_destroy(&pEnc->sReference, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height);
188          image_destroy(&pEnc->vInterH, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height);          image_destroy(&pEnc->vInterH, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height);
189          image_destroy(&pEnc->vInterV, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height);          image_destroy(&pEnc->vInterV, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height);
190            image_destroy(&pEnc->vInterVf, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height);
191          image_destroy(&pEnc->vInterHV, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height);          image_destroy(&pEnc->vInterHV, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height);
192            image_destroy(&pEnc->vInterHVf, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height);
193          xvid_free(pEnc);          xvid_free(pEnc);
194    
         destroy_vlc_tables();  
   
195          return XVID_ERR_OK;          return XVID_ERR_OK;
196  }  }
197    
# Line 212  Line 211 
211    
212          pEnc->mbParam.global_flags = pFrame->general;          pEnc->mbParam.global_flags = pFrame->general;
213          pEnc->mbParam.motion_flags = pFrame->motion;          pEnc->mbParam.motion_flags = pFrame->motion;
214            pEnc->mbParam.hint = &pFrame->hint;
215    
216          start_timer();          start_timer();
217          if (image_input(&pEnc->sCurrent, pEnc->mbParam.width, pEnc->mbParam.height, pEnc->mbParam.edged_width,          if (image_input(&pEnc->sCurrent, pEnc->mbParam.width, pEnc->mbParam.height, pEnc->mbParam.edged_width,
# Line 241  Line 241 
241                  pEnc->mbParam.quant = adaptive_quantization(pEnc->sCurrent.y,                  pEnc->mbParam.quant = adaptive_quantization(pEnc->sCurrent.y,
242                                                              pEnc->mbParam.width,                                                              pEnc->mbParam.width,
243                                                              temp_dquants,                                                              temp_dquants,
244                                                              pFrame->quant,                                                              pEnc->mbParam.quant,
245                                                              pFrame->quant,                                                              pEnc->mbParam.quant,
246                                                              2*pFrame->quant,                                                              2*pEnc->mbParam.quant,
247                                                              pEnc->mbParam.mb_width,                                                              pEnc->mbParam.mb_width,
248                                                              pEnc->mbParam.mb_height);                                                              pEnc->mbParam.mb_height);
249    
# Line 352  Line 352 
352  }  }
353    
354    
355    #define FCODEBITS       3
356    #define MODEBITS        5
357    
358    void HintedMESet(Encoder * pEnc, int * intra)
359    {
360            HINTINFO * hint;
361            Bitstream bs;
362            int length, high;
363            uint32_t x, y;
364    
365            hint = pEnc->mbParam.hint;
366    
367            if (hint->rawhints)
368            {
369                    *intra = hint->mvhint.intra;
370            }
371            else
372            {
373                    BitstreamInit(&bs, hint->hintstream, hint->hintlength);
374                    *intra = BitstreamGetBit(&bs);
375            }
376    
377            if (*intra)
378            {
379                    return;
380            }
381    
382            pEnc->mbParam.fixed_code = (hint->rawhints) ? hint->mvhint.fcode : BitstreamGetBits(&bs, FCODEBITS);
383    
384            length  = pEnc->mbParam.fixed_code + 5;
385            high    = 1 << (length - 1);
386    
387            for (y=0 ; y<pEnc->mbParam.mb_height ; ++y)
388            {
389                    for (x=0 ; x<pEnc->mbParam.mb_width ; ++x)
390                    {
391                            MACROBLOCK * pMB = &pEnc->pMBs[x + y * pEnc->mbParam.mb_width];
392                            MVBLOCKHINT * bhint = &hint->mvhint.block[x + y * pEnc->mbParam.mb_width];
393                            VECTOR pred[4];
394                            VECTOR tmp;
395                            int dummy[4];
396                            int vec;
397    
398                            pMB->mode = (hint->rawhints) ? bhint->mode : BitstreamGetBits(&bs, MODEBITS);
399    
400                            if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)
401                            {
402                                    tmp.x  = (hint->rawhints) ? bhint->mvs[0].x : BitstreamGetBits(&bs, length);
403                                    tmp.y  = (hint->rawhints) ? bhint->mvs[0].y : BitstreamGetBits(&bs, length);
404                                    tmp.x -= (tmp.x >= high) ? high*2 : 0;
405                                    tmp.y -= (tmp.y >= high) ? high*2 : 0;
406    
407                                    get_pmvdata(pEnc->pMBs, x, y, pEnc->mbParam.mb_width, 0, pred, dummy);
408    
409                                    for (vec=0 ; vec<4 ; ++vec)
410                                    {
411                                            pMB->mvs[vec].x  = tmp.x;
412                                            pMB->mvs[vec].y  = tmp.y;
413                                            pMB->pmvs[vec].x = pMB->mvs[0].x - pred[0].x;
414                                            pMB->pmvs[vec].y = pMB->mvs[0].y - pred[0].y;
415                                    }
416                            }
417                            else if (pMB->mode == MODE_INTER4V)
418                            {
419                                    for (vec=0 ; vec<4 ; ++vec)
420                                    {
421                                            tmp.x  = (hint->rawhints) ? bhint->mvs[vec].x : BitstreamGetBits(&bs, length);
422                                            tmp.y  = (hint->rawhints) ? bhint->mvs[vec].y : BitstreamGetBits(&bs, length);
423                                            tmp.x -= (tmp.x >= high) ? high*2 : 0;
424                                            tmp.y -= (tmp.y >= high) ? high*2 : 0;
425    
426                                            get_pmvdata(pEnc->pMBs, x, y, pEnc->mbParam.mb_width, vec, pred, dummy);
427    
428                                            pMB->mvs[vec].x  = tmp.x;
429                                            pMB->mvs[vec].y  = tmp.y;
430                                            pMB->pmvs[vec].x = pMB->mvs[vec].x - pred[0].x;
431                                            pMB->pmvs[vec].y = pMB->mvs[vec].y - pred[0].y;
432                                    }
433                            }
434                            else    // intra / intra_q / stuffing / not_coded
435                            {
436                                    for (vec=0 ; vec<4 ; ++vec)
437                                    {
438                                            pMB->mvs[vec].x  = pMB->mvs[vec].y  = 0;
439                                    }
440                            }
441                    }
442            }
443    }
444    
445    
446    void HintedMEGet(Encoder * pEnc, int intra)
447    {
448            HINTINFO * hint;
449            Bitstream bs;
450            uint32_t x, y;
451            int length, high;
452    
453            hint = pEnc->mbParam.hint;
454    
455            if (hint->rawhints)
456            {
457                    hint->mvhint.intra = intra;
458            }
459            else
460            {
461                    BitstreamInit(&bs, hint->hintstream, 0);
462                    BitstreamPutBit(&bs, intra);
463            }
464    
465            if (intra)
466            {
467                    if (!hint->rawhints)
468                    {
469                            BitstreamPad(&bs);
470                            hint->hintlength = BitstreamLength(&bs);
471                    }
472                    return;
473            }
474    
475            length  = pEnc->mbParam.fixed_code + 5;
476            high    = 1 << (length - 1);
477    
478            if (hint->rawhints)
479            {
480                    hint->mvhint.fcode = pEnc->mbParam.fixed_code;
481            }
482            else
483            {
484                    BitstreamPutBits(&bs, pEnc->mbParam.fixed_code, FCODEBITS);
485            }
486    
487            for (y=0 ; y<pEnc->mbParam.mb_height ; ++y)
488            {
489                    for (x=0 ; x<pEnc->mbParam.mb_width ; ++x)
490                    {
491                            MACROBLOCK * pMB = &pEnc->pMBs[x + y * pEnc->mbParam.mb_width];
492                            MVBLOCKHINT * bhint = &hint->mvhint.block[x + y * pEnc->mbParam.mb_width];
493                            VECTOR tmp;
494    
495                            if (hint->rawhints)
496                            {
497                                    bhint->mode = pMB->mode;
498                            }
499                            else
500                            {
501                                    BitstreamPutBits(&bs, pMB->mode, MODEBITS);
502                            }
503    
504                            if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)
505                            {
506                                    tmp.x  = pMB->mvs[0].x;
507                                    tmp.y  = pMB->mvs[0].y;
508                                    tmp.x += (tmp.x < 0) ? high*2 : 0;
509                                    tmp.y += (tmp.y < 0) ? high*2 : 0;
510    
511                                    if (hint->rawhints)
512                                    {
513                                            bhint->mvs[0].x = tmp.x;
514                                            bhint->mvs[0].y = tmp.y;
515                                    }
516                                    else
517                                    {
518                                            BitstreamPutBits(&bs, tmp.x, length);
519                                            BitstreamPutBits(&bs, tmp.y, length);
520                                    }
521                            }
522                            else if (pMB->mode == MODE_INTER4V)
523                            {
524                                    int vec;
525    
526                                    for (vec=0 ; vec<4 ; ++vec)
527                                    {
528                                            tmp.x  = pMB->mvs[vec].x;
529                                            tmp.y  = pMB->mvs[vec].y;
530                                            tmp.x += (tmp.x < 0) ? high*2 : 0;
531                                            tmp.y += (tmp.y < 0) ? high*2 : 0;
532    
533                                            if (hint->rawhints)
534                                            {
535                                                    bhint->mvs[vec].x = tmp.x;
536                                                    bhint->mvs[vec].y = tmp.y;
537                                            }
538                                            else
539                                            {
540                                                    BitstreamPutBits(&bs, tmp.x, length);
541                                                    BitstreamPutBits(&bs, tmp.y, length);
542                                            }
543                                    }
544                            }
545                    }
546            }
547    
548            if (!hint->rawhints)
549            {
550                    BitstreamPad(&bs);
551                    hint->hintlength = BitstreamLength(&bs);
552            }
553    }
554    
555    
556  static int FrameCodeI(Encoder * pEnc, Bitstream * bs, uint32_t *pBits)  static int FrameCodeI(Encoder * pEnc, Bitstream * bs, uint32_t *pBits)
557  {  {
558    
# Line 399  Line 600 
600          pEnc->sStat.iMvCount = 0;          pEnc->sStat.iMvCount = 0;
601          pEnc->mbParam.fixed_code = 2;          pEnc->mbParam.fixed_code = 2;
602    
603            if (pEnc->mbParam.global_flags & XVID_HINTEDME_GET)
604            {
605                    HintedMEGet(pEnc, 1);
606            }
607    
608          return 1;                                        // intra          return 1;                                        // intra
609  }  }
610    
# Line 445  Line 651 
651          }          }
652    
653          start_timer();          start_timer();
654            if (pEnc->mbParam.global_flags & XVID_HINTEDME_SET)
655            {
656                    HintedMESet(pEnc, &bIntra);
657            }
658            else
659            {
660          bIntra = MotionEstimation(pEnc->pMBs, &pEnc->mbParam, &pEnc->sReference,          bIntra = MotionEstimation(pEnc->pMBs, &pEnc->mbParam, &pEnc->sReference,
661                                    &pEnc->vInterH, &pEnc->vInterV,                                    &pEnc->vInterH, &pEnc->vInterV,
662                                    &pEnc->vInterHV, &pEnc->sCurrent, iLimit);                                    &pEnc->vInterHV, &pEnc->sCurrent, iLimit);
663            }
664          stop_motion_timer();          stop_motion_timer();
665    
666          if (bIntra == 1)          if (bIntra == 1)
667            {
668                  return FrameCodeI(pEnc, bs, pBits);                  return FrameCodeI(pEnc, bs, pBits);
669            }
670    
671          pEnc->mbParam.coding_type = P_VOP;          pEnc->mbParam.coding_type = P_VOP;
672    
# Line 541  Line 756 
756    
757          emms();          emms();
758    
759            if (pEnc->mbParam.global_flags & XVID_HINTEDME_GET)
760            {
761                    HintedMEGet(pEnc, 0);
762            }
763    
764          if (pEnc->sStat.iMvCount == 0)          if (pEnc->sStat.iMvCount == 0)
765                  pEnc->sStat.iMvCount = 1;                  pEnc->sStat.iMvCount = 1;
766    

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.22

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4