[svn] / branches / dev-api-3 / xvidcore / src / encoder.c Repository:
ViewVC logotype

Diff of /branches/dev-api-3/xvidcore/src/encoder.c

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

revision 100, Thu Apr 4 13:58:18 2002 UTC revision 101, Fri Apr 5 14:40:36 2002 UTC
# Line 211  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 402  Line 403 
403  }  }
404    
405    
406    #define FCODEBITS       3
407    #define MODEBITS        5
408    
409    void HintedMESet(Encoder * pEnc, int * intra)
410    {
411            HINTINFO * hint;
412            Bitstream bs;
413            int length, high;
414            uint32_t x, y;
415    
416            hint = pEnc->mbParam.hint;
417    
418            if (hint->rawhints)
419            {
420                    *intra = hint->mvhint.intra;
421            }
422            else
423            {
424                    BitstreamInit(&bs, hint->hintstream, hint->hintlength);
425                    *intra = BitstreamGetBit(&bs);
426            }
427    
428            if (*intra)
429            {
430                    return;
431            }
432    
433            pEnc->mbParam.fixed_code = (hint->rawhints) ? hint->mvhint.fcode : BitstreamGetBits(&bs, FCODEBITS);
434    
435            length  = pEnc->mbParam.fixed_code + 5;
436            high    = 1 << (length - 1);
437    
438            for (y=0 ; y<pEnc->mbParam.mb_height ; ++y)
439            {
440                    for (x=0 ; x<pEnc->mbParam.mb_width ; ++x)
441                    {
442                            MACROBLOCK * pMB = &pEnc->pMBs[x + y * pEnc->mbParam.mb_width];
443                            MVBLOCKHINT * bhint = &hint->mvhint.block[x + y * pEnc->mbParam.mb_width];
444                            VECTOR pred[4];
445                            VECTOR tmp;
446                            int dummy[4];
447                            int vec;
448    
449                            pMB->mode = (hint->rawhints) ? bhint->mode : BitstreamGetBits(&bs, MODEBITS);
450    
451                            if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)
452                            {
453                                    tmp.x  = (hint->rawhints) ? bhint->mvs[0].x : BitstreamGetBits(&bs, length);
454                                    tmp.y  = (hint->rawhints) ? bhint->mvs[0].y : BitstreamGetBits(&bs, length);
455                                    tmp.x -= (tmp.x >= high) ? high*2 : 0;
456                                    tmp.y -= (tmp.y >= high) ? high*2 : 0;
457    
458                                    get_pmvdata(pEnc->pMBs, x, y, pEnc->mbParam.mb_width, 0, pred, dummy);
459    
460                                    for (vec=0 ; vec<4 ; ++vec)
461                                    {
462                                            pMB->mvs[vec].x  = tmp.x;
463                                            pMB->mvs[vec].y  = tmp.y;
464                                            pMB->pmvs[vec].x = pMB->mvs[0].x - pred[0].x;
465                                            pMB->pmvs[vec].y = pMB->mvs[0].y - pred[0].y;
466                                    }
467                            }
468                            else if (pMB->mode == MODE_INTER4V)
469                            {
470                                    for (vec=0 ; vec<4 ; ++vec)
471                                    {
472                                            tmp.x  = (hint->rawhints) ? bhint->mvs[vec].x : BitstreamGetBits(&bs, length);
473                                            tmp.y  = (hint->rawhints) ? bhint->mvs[vec].y : BitstreamGetBits(&bs, length);
474                                            tmp.x -= (tmp.x >= high) ? high*2 : 0;
475                                            tmp.y -= (tmp.y >= high) ? high*2 : 0;
476    
477                                            get_pmvdata(pEnc->pMBs, x, y, pEnc->mbParam.mb_width, vec, pred, dummy);
478    
479                                            pMB->mvs[vec].x  = tmp.x;
480                                            pMB->mvs[vec].y  = tmp.y;
481                                            pMB->pmvs[vec].x = pMB->mvs[vec].x - pred[0].x;
482                                            pMB->pmvs[vec].y = pMB->mvs[vec].y - pred[0].y;
483                                    }
484                            }
485                            else    // intra / intra_q / stuffing / not_coded
486                            {
487                                    for (vec=0 ; vec<4 ; ++vec)
488                                    {
489                                            pMB->mvs[vec].x  = pMB->mvs[vec].y  = 0;
490                                    }
491                            }
492                    }
493            }
494    }
495    
496    
497    void HintedMEGet(Encoder * pEnc, int intra)
498    {
499            HINTINFO * hint;
500            Bitstream bs;
501            uint32_t x, y;
502            int length, high;
503    
504            hint = pEnc->mbParam.hint;
505    
506            if (hint->rawhints)
507            {
508                    hint->mvhint.intra = intra;
509            }
510            else
511            {
512                    BitstreamInit(&bs, hint->hintstream, 0);
513                    BitstreamPutBit(&bs, intra);
514            }
515    
516            if (intra)
517            {
518                    if (!hint->rawhints)
519                    {
520                            BitstreamPad(&bs);
521                            hint->hintlength = BitstreamLength(&bs);
522                    }
523                    return;
524            }
525    
526            length  = pEnc->mbParam.fixed_code + 5;
527            high    = 1 << (length - 1);
528    
529            if (hint->rawhints)
530            {
531                    hint->mvhint.fcode = pEnc->mbParam.fixed_code;
532            }
533            else
534            {
535                    BitstreamPutBits(&bs, pEnc->mbParam.fixed_code, FCODEBITS);
536            }
537    
538            for (y=0 ; y<pEnc->mbParam.mb_height ; ++y)
539            {
540                    for (x=0 ; x<pEnc->mbParam.mb_width ; ++x)
541                    {
542                            MACROBLOCK * pMB = &pEnc->pMBs[x + y * pEnc->mbParam.mb_width];
543                            MVBLOCKHINT * bhint = &hint->mvhint.block[x + y * pEnc->mbParam.mb_width];
544                            VECTOR tmp;
545    
546                            if (hint->rawhints)
547                            {
548                                    bhint->mode = pMB->mode;
549                            }
550                            else
551                            {
552                                    BitstreamPutBits(&bs, pMB->mode, MODEBITS);
553                            }
554    
555                            if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)
556                            {
557                                    tmp.x  = pMB->mvs[0].x;
558                                    tmp.y  = pMB->mvs[0].y;
559                                    tmp.x += (tmp.x < 0) ? high*2 : 0;
560                                    tmp.y += (tmp.y < 0) ? high*2 : 0;
561    
562                                    if (hint->rawhints)
563                                    {
564                                            bhint->mvs[0].x = tmp.x;
565                                            bhint->mvs[0].y = tmp.y;
566                                    }
567                                    else
568                                    {
569                                            BitstreamPutBits(&bs, tmp.x, length);
570                                            BitstreamPutBits(&bs, tmp.y, length);
571                                    }
572                            }
573                            else if (pMB->mode == MODE_INTER4V)
574                            {
575                                    int vec;
576    
577                                    for (vec=0 ; vec<4 ; ++vec)
578                                    {
579                                            tmp.x  = pMB->mvs[vec].x;
580                                            tmp.y  = pMB->mvs[vec].y;
581                                            tmp.x += (tmp.x < 0) ? high*2 : 0;
582                                            tmp.y += (tmp.y < 0) ? high*2 : 0;
583    
584                                            if (hint->rawhints)
585                                            {
586                                                    bhint->mvs[vec].x = tmp.x;
587                                                    bhint->mvs[vec].y = tmp.y;
588                                            }
589                                            else
590                                            {
591                                                    BitstreamPutBits(&bs, tmp.x, length);
592                                                    BitstreamPutBits(&bs, tmp.y, length);
593                                            }
594                                    }
595                            }
596                    }
597            }
598    
599            if (!hint->rawhints)
600            {
601                    BitstreamPad(&bs);
602                    hint->hintlength = BitstreamLength(&bs);
603            }
604    }
605    
606    
607  #define INTRA_THRESHOLD 0.5  #define INTRA_THRESHOLD 0.5
608    
609  static int FrameCodeP(Encoder * pEnc, Bitstream * bs, uint32_t *pBits, bool force_inter, bool vol_header)  static int FrameCodeP(Encoder * pEnc, Bitstream * bs, uint32_t *pBits, bool force_inter, bool vol_header)
# Line 444  Line 646 
646          }          }
647    
648          start_timer();          start_timer();
649            if (pEnc->mbParam.global_flags & XVID_HINTEDME_SET)
650            {
651                    HintedMESet(pEnc, &bIntra);
652            }
653            else
654            {
655          bIntra = MotionEstimation(pEnc->pMBs, &pEnc->mbParam, &pEnc->sReference,          bIntra = MotionEstimation(pEnc->pMBs, &pEnc->mbParam, &pEnc->sReference,
656                                    &pEnc->vInterH, &pEnc->vInterV,                                    &pEnc->vInterH, &pEnc->vInterV,
657                                    &pEnc->vInterHV, &pEnc->sCurrent, iLimit);                                    &pEnc->vInterHV, &pEnc->sCurrent, iLimit);
658            }
659          stop_motion_timer();          stop_motion_timer();
660    
661          if (bIntra == 1)          if (bIntra == 1)
662            {
663                    if (pEnc->mbParam.global_flags & XVID_HINTEDME_GET)
664                    {
665                            HintedMEGet(pEnc, 1);
666                    }
667                  return FrameCodeI(pEnc, bs, pBits);                  return FrameCodeI(pEnc, bs, pBits);
668            }
669    
670          pEnc->mbParam.coding_type = P_VOP;          pEnc->mbParam.coding_type = P_VOP;
671    
# Line 540  Line 755 
755    
756          emms();          emms();
757    
758            if (pEnc->mbParam.global_flags & XVID_HINTEDME_GET)
759            {
760                    HintedMEGet(pEnc, 0);
761            }
762    
763          if (pEnc->sStat.iMvCount == 0)          if (pEnc->sStat.iMvCount == 0)
764                  pEnc->sStat.iMvCount = 1;                  pEnc->sStat.iMvCount = 1;
765    

Legend:
Removed from v.100  
changed lines
  Added in v.101

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