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

Diff of /trunk/xvidcore/src/encoder.c

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

revision 195, Wed Jun 12 20:38:41 2002 UTC revision 233, Sat Jun 22 07:23:10 2002 UTC
# Line 32  Line 32 
32   *   *
33   *  History   *  History
34   *   *
35     *      20.06.2002 bframe patch
36   *  08.05.2002 fix some problem in DEBUG mode;   *  08.05.2002 fix some problem in DEBUG mode;
37   *             MinChen <chenm001@163.com>   *             MinChen <chenm001@163.com>
38   *  14.04.2002 added FrameCodeB()   *  14.04.2002 added FrameCodeB()
39   *   *
40   *  $Id: encoder.c,v 1.41 2002-06-12 20:38:40 edgomez Exp $   *  $Id: encoder.c,v 1.45 2002-06-22 07:23:10 suxen_drol Exp $
41   *   *
42   ****************************************************************************/   ****************************************************************************/
43    
44  #include <stdlib.h>  #include <stdlib.h>
45  #include <stdio.h>  #include <stdio.h>
46  #include <math.h>  #include <math.h>
47    #include <string.h>
48    
49  #include "encoder.h"  #include "encoder.h"
50  #include "prediction/mbprediction.h"  #include "prediction/mbprediction.h"
# Line 131  Line 133 
133  encoder_create(XVID_ENC_PARAM * pParam)  encoder_create(XVID_ENC_PARAM * pParam)
134  {  {
135          Encoder *pEnc;          Encoder *pEnc;
136          uint32_t i;          int i;
137    
138          pParam->handle = NULL;          pParam->handle = NULL;
139    
# Line 207  Line 209 
209          if (pEnc == NULL)          if (pEnc == NULL)
210                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
211    
212            /* Zero the Encoder Structure */
213    
214            memset(pEnc, 0, sizeof(Encoder));
215    
216          /* Fill members of Encoder structure */          /* Fill members of Encoder structure */
217    
218          pEnc->mbParam.width = pParam->width;          pEnc->mbParam.width = pParam->width;
# Line 221  Line 227 
227          pEnc->mbParam.fbase = pParam->fbase;          pEnc->mbParam.fbase = pParam->fbase;
228          pEnc->mbParam.fincr = pParam->fincr;          pEnc->mbParam.fincr = pParam->fincr;
229    
230            pEnc->mbParam.m_quant_type = H263_QUANT;
231    
232          pEnc->sStat.fMvPrevSigma = -1;          pEnc->sStat.fMvPrevSigma = -1;
233    
234          /* Fill rate control parameters */          /* Fill rate control parameters */
# Line 252  Line 260 
260    
261          /* try to allocate image memory */          /* try to allocate image memory */
262    
263  #ifdef _DEBUG  #ifdef _DEBUG_PSNR
264          image_null(&pEnc->sOriginal);          image_null(&pEnc->sOriginal);
265  #endif  #endif
266  #ifdef BFRAMES  #ifdef BFRAMES
# Line 268  Line 276 
276          image_null(&pEnc->vInterHV);          image_null(&pEnc->vInterHV);
277          image_null(&pEnc->vInterHVf);          image_null(&pEnc->vInterHVf);
278    
279  #ifdef _DEBUG  #ifdef _DEBUG_PSNR
280          if (image_create          if (image_create
281                  (&pEnc->sOriginal, pEnc->mbParam.edged_width,                  (&pEnc->sOriginal, pEnc->mbParam.edged_width,
282                   pEnc->mbParam.edged_height) < 0)                   pEnc->mbParam.edged_height) < 0)
# Line 322  Line 330 
330          /* B Frames specific init */          /* B Frames specific init */
331  #ifdef BFRAMES  #ifdef BFRAMES
332    
333            pEnc->packed = pParam->packed;
334          pEnc->mbParam.max_bframes = pParam->max_bframes;          pEnc->mbParam.max_bframes = pParam->max_bframes;
335          pEnc->bquant_ratio = pParam->bquant_ratio;          pEnc->bquant_ratio = pParam->bquant_ratio;
336          pEnc->bframes = NULL;          pEnc->bframes = NULL;
# Line 367  Line 376 
376          pEnc->bframenum_tail = 0;          pEnc->bframenum_tail = 0;
377          pEnc->flush_bframes = 0;          pEnc->flush_bframes = 0;
378    
379            pEnc->queue = NULL;
380    
381    
382            if (pEnc->mbParam.max_bframes > 0) {
383                    int n;
384    
385                    pEnc->queue =
386                            xvid_malloc(pEnc->mbParam.max_bframes * sizeof(IMAGE),
387                                                    CACHE_LINE);
388    
389                    if (pEnc->queue == NULL)
390                            goto xvid_err_memory4;
391    
392                    for (n = 0; n < pEnc->mbParam.max_bframes; n++)
393                            image_null(&pEnc->queue[n]);
394    
395                    for (n = 0; n < pEnc->mbParam.max_bframes; n++) {
396                            if (image_create
397                                    (&pEnc->queue[n], pEnc->mbParam.edged_width,
398                                     pEnc->mbParam.edged_height) < 0)
399                                    goto xvid_err_memory5;
400    
401                    }
402            }
403    
404            pEnc->queue_head = 0;
405            pEnc->queue_tail = 0;
406            pEnc->queue_size = 0;
407    
408    
409          pEnc->mbParam.m_seconds = 0;          pEnc->mbParam.m_seconds = 0;
410          pEnc->mbParam.m_ticks = 0;          pEnc->mbParam.m_ticks = 0;
411  #endif  #endif
# Line 389  Line 428 
428           * We handle all XVID_ERR_MEMORY here, this makes the code lighter           * We handle all XVID_ERR_MEMORY here, this makes the code lighter
429           */           */
430  #ifdef BFRAMES  #ifdef BFRAMES
431      xvid_err_memory5:
432    
433    
434            if (pEnc->mbParam.max_bframes > 0) {
435    
436                    for (i = 0; i < pEnc->mbParam.max_bframes; i++) {
437                            image_destroy(&pEnc->queue[i], pEnc->mbParam.edged_width,
438                                                      pEnc->mbParam.edged_height);
439                    }
440                    xvid_free(pEnc->queue);
441            }
442    
443    xvid_err_memory4:    xvid_err_memory4:
444    
445            if (pEnc->mbParam.max_bframes > 0) {
446    
447          for (i = 0; i < pEnc->mbParam.max_bframes; i++) {          for (i = 0; i < pEnc->mbParam.max_bframes; i++) {
448    
449                  if (pEnc->bframes[i] == NULL)                  if (pEnc->bframes[i] == NULL)
# Line 405  Line 459 
459          }          }
460    
461          xvid_free(pEnc->bframes);          xvid_free(pEnc->bframes);
462            }
463    
464  #endif  #endif
465    
466    xvid_err_memory3:    xvid_err_memory3:
467  #ifdef _DEBUG  #ifdef _DEBUG_PSNR
468          image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width,          image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width,
469                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
470  #endif  #endif
# Line 466  Line 521 
521  int  int
522  encoder_destroy(Encoder * pEnc)  encoder_destroy(Encoder * pEnc)
523  {  {
524    #ifdef BFRAMES
525            int i;
526    #endif
527    
528          ENC_CHECK(pEnc);          ENC_CHECK(pEnc);
529    
530          /* B Frames specific */          /* B Frames specific */
531  #ifdef BFRAMES  #ifdef BFRAMES
532          int i;          if (pEnc->mbParam.max_bframes > 0) {
533    
534                    for (i = 0; i < pEnc->mbParam.max_bframes; i++) {
535    
536                            image_destroy(&pEnc->queue[i], pEnc->mbParam.edged_width,
537                                              pEnc->mbParam.edged_height);
538                    }
539                    xvid_free(pEnc->queue);
540            }
541    
542    
543            if (pEnc->mbParam.max_bframes > 0) {
544    
545          for (i = 0; i < pEnc->mbParam.max_bframes; i++) {          for (i = 0; i < pEnc->mbParam.max_bframes; i++) {
546    
# Line 483  Line 553 
553                  xvid_free(pEnc->bframes[i]->mbs);                  xvid_free(pEnc->bframes[i]->mbs);
554    
555                  xvid_free(pEnc->bframes[i]);                  xvid_free(pEnc->bframes[i]);
   
556          }          }
557    
558          xvid_free(pEnc->bframes);          xvid_free(pEnc->bframes);
559    
560            }
561  #endif  #endif
562    
563          /* All images, reference, current etc ... */          /* All images, reference, current etc ... */
# Line 514  Line 584 
584          image_destroy(&pEnc->f_refhv, pEnc->mbParam.edged_width,          image_destroy(&pEnc->f_refhv, pEnc->mbParam.edged_width,
585                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
586  #endif  #endif
587  #ifdef _DEBUG  #ifdef _DEBUG_PSNR
588          image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width,          image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width,
589                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
590  #endif  #endif
# Line 532  Line 602 
602          return XVID_ERR_OK;          return XVID_ERR_OK;
603  }  }
604    
605    
606    #ifdef BFRAMES
607    void inc_frame_num(Encoder * pEnc)
608    {
609            pEnc->iFrameNum++;
610            pEnc->mbParam.m_ticks += pEnc->mbParam.fincr;
611            if (pEnc->mbParam.m_ticks > pEnc->mbParam.fbase) {
612                    pEnc->mbParam.m_seconds = pEnc->mbParam.m_ticks % pEnc->mbParam.fbase;
613                    pEnc->mbParam.m_ticks = pEnc->mbParam.m_ticks % pEnc->mbParam.fbase;
614            }
615    }
616    #endif
617    
618    
619    #ifdef BFRAMES
620    void queue_image(Encoder * pEnc, XVID_ENC_FRAME * pFrame)
621    {
622            if (pEnc->queue_size >= pEnc->mbParam.max_bframes)
623            {
624                    DPRINTF("FATAL: QUEUE FULL");
625                    return;
626            }
627    
628            DPRINTF("*** QUEUE bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
629                                    pEnc->bframenum_head, pEnc->bframenum_tail,
630                                    pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
631    
632    
633            start_timer();
634            if (image_input
635                    (&pEnc->queue[pEnc->queue_tail], pEnc->mbParam.width, pEnc->mbParam.height,
636                     pEnc->mbParam.edged_width, pFrame->image, pFrame->colorspace))
637                    return;
638            stop_conv_timer();
639    
640            pEnc->queue_size++;
641            pEnc->queue_tail =  (pEnc->queue_tail + 1) % pEnc->mbParam.max_bframes;
642    }
643    #endif
644    
645    
646    #ifdef BFRAMES
647  /*****************************************************************************  /*****************************************************************************
648   * Frame encoder entry point   * IPB frame encoder entry point
  *  
  * At this moment 2 versions coexist : one for IPB compatible encoder,  
  *                                     another one for the old IP encoder.  
649   *   *
650   * Returned values :   * Returned values :
651   *    - XVID_ERR_OK     - no errors   *    - XVID_ERR_OK     - no errors
# Line 544  Line 653 
653   *                        format   *                        format
654   ****************************************************************************/   ****************************************************************************/
655    
   
 #ifdef BFRAMES  
 /*****************************************************************************  
  * Frame encoder entry point for IPB capable encoder  
  ****************************************************************************/  
656  int  int
657  encoder_encode(Encoder * pEnc,  encoder_encode_bframes(Encoder * pEnc,
658                             XVID_ENC_FRAME * pFrame,                             XVID_ENC_FRAME * pFrame,
659                             XVID_ENC_STATS * pResult)                             XVID_ENC_STATS * pResult)
660  {  {
# Line 558  Line 662 
662          Bitstream bs;          Bitstream bs;
663          uint32_t bits;          uint32_t bits;
664    
665  #ifdef _DEBUG          int input_valid = 1;
666    
667    #ifdef _DEBUG_PSNR
668          float psnr;          float psnr;
669          char temp[128];          char temp[128];
670  #endif  #endif
671    
672          ENC_CHECK(pEnc);          ENC_CHECK(pEnc);
673          ENC_CHECK(pFrame);          ENC_CHECK(pFrame);
674            ENC_CHECK(pFrame->image);
675    
676          start_global_timer();          start_global_timer();
677    
678          BitstreamInit(&bs, pFrame->bitstream, 0);          BitstreamInit(&bs, pFrame->bitstream, 0);
679    
680    ipvop_loop:
681    
682          /*          /*
683           * bframe "flush" code           * bframe "flush" code
684           */           */
# Line 584  Line 693 
693                           * frame as a pframe                           * frame as a pframe
694                           */                           */
695    
696                          /* ToDo : remove dprintf calls */                          DPRINTF("*** BFRAME (final frame) bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
697                          /*                                  pEnc->bframenum_head, pEnc->bframenum_tail,
698                             dprintf("--- PFRAME (final frame correction) --- ");                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
699                           */  
700                          pEnc->bframenum_tail--;                          pEnc->bframenum_tail--;
701                          SWAP(pEnc->current, pEnc->reference);                          SWAP(pEnc->current, pEnc->reference);
702    
# Line 597  Line 706 
706    
707                          BitstreamPad(&bs);                          BitstreamPad(&bs);
708                          pFrame->length = BitstreamLength(&bs);                          pFrame->length = BitstreamLength(&bs);
                         pFrame->input_consumed = 0;  
709                          pFrame->intra = 0;                          pFrame->intra = 0;
710    
711                          return XVID_ERR_OK;                          return XVID_ERR_OK;
712                  }                  }
713    
714                  /* ToDo : remove dprintf calls */  
715                  /*                  DPRINTF("*** BFRAME (flush) bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
716                     dprintf("--- BFRAME (flush) --- ");                                  pEnc->bframenum_head, pEnc->bframenum_tail,
717                   */                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
718    
719                  FrameCodeB(pEnc, pEnc->bframes[pEnc->bframenum_head], &bs, &bits);                  FrameCodeB(pEnc, pEnc->bframes[pEnc->bframenum_head], &bs, &bits);
720                  pEnc->bframenum_head++;                  pEnc->bframenum_head++;
721    
   
722                  BitstreamPad(&bs);                  BitstreamPad(&bs);
723                  pFrame->length = BitstreamLength(&bs);                  pFrame->length = BitstreamLength(&bs);
                 pFrame->input_consumed = 0;  
724                  pFrame->intra = 0;                  pFrame->intra = 0;
725    
726                    if (input_valid)
727                            queue_image(pEnc, pFrame);
728    
729                  return XVID_ERR_OK;                  return XVID_ERR_OK;
730          }          }
731    
732          if (pFrame->image == NULL) {          if (pEnc->bframenum_head > 0) {
733                  pFrame->length = 0;                  pEnc->bframenum_head = pEnc->bframenum_tail = 0;
734                  pFrame->input_consumed = 1;  
735                    if (pEnc->packed) {
736    
737                            DPRINTF("*** EMPTY bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
738                                    pEnc->bframenum_head, pEnc->bframenum_tail,
739                                    pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
740    
741    
742                            BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0);
743                            BitstreamPad(&bs);
744                            BitstreamPutBits(&bs, 0x7f, 8);
745    
746                            pFrame->length = BitstreamLength(&bs);
747                  pFrame->intra = 0;                  pFrame->intra = 0;
748    
749                            if (input_valid)
750                                    queue_image(pEnc, pFrame);
751    
752                  return XVID_ERR_OK;                  return XVID_ERR_OK;
753          }          }
754            }
755    
756          if (pEnc->bframenum_head > 0) {  
757                  pEnc->bframenum_head = pEnc->bframenum_tail = 0;  bvop_loop:
758    
759            if (input_valid) {
760    
761                    SWAP(pEnc->current, pEnc->reference);
762    
763                    start_timer();
764                    if (image_input
765                            (&pEnc->current->image, pEnc->mbParam.width, pEnc->mbParam.height,
766                            pEnc->mbParam.edged_width, pFrame->image, pFrame->colorspace))
767                            return XVID_ERR_FORMAT;
768                    stop_conv_timer();
769    
770                    // queue input frame, and dequue next image
771                    if (pEnc->queue_size > 0)
772                    {
773                            image_swap(&pEnc->current->image, &pEnc->queue[pEnc->queue_tail]);
774                            if (pEnc->queue_head != pEnc->queue_tail)
775                            {
776                                    image_swap(&pEnc->current->image, &pEnc->queue[pEnc->queue_head]);
777                            }
778                            pEnc->queue_head =  (pEnc->queue_head + 1) % pEnc->mbParam.max_bframes;
779                            pEnc->queue_tail =  (pEnc->queue_tail + 1) % pEnc->mbParam.max_bframes;
780                    }
781    
782            } else if (pEnc->queue_size > 0) {
783    
784                    SWAP(pEnc->current, pEnc->reference);
785    
786                    image_swap(&pEnc->current->image, &pEnc->queue[pEnc->queue_head]);
787                    pEnc->queue_head =  (pEnc->queue_head + 1) % pEnc->mbParam.max_bframes;
788                    pEnc->queue_size--;
789    
790            } else if (BitstreamPos(&bs) == 0) {
791    
792                    DPRINTF("*** SKIP bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
793                                    pEnc->bframenum_head, pEnc->bframenum_tail,
794                                    pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
795    
796    
797                    pFrame->intra = 0;
798    
799                    BitstreamPutBits(&bs, 0x7f, 8);
800                    BitstreamPad(&bs);
801                    pFrame->length = BitstreamLength(&bs);
802    
803                    return XVID_ERR_OK;
804    
805            } else {
806    
807                    pFrame->length = BitstreamLength(&bs);
808                    return XVID_ERR_OK;
809          }          }
810    
811          pEnc->flush_bframes = 0;          pEnc->flush_bframes = 0;
# Line 638  Line 815 
815           * comment style :-)           * comment style :-)
816           * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */           * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
817    
818          SWAP(pEnc->current, pEnc->reference);  //$$    SWAP(pEnc->current, pEnc->reference);
819    
820          EMMS();          emms();
821    
822          if (pFrame->quant == 0)          if (pFrame->quant == 0)
823                  pEnc->current->quant = RateControlGetQ(&pEnc->rate_control, 0);                  pEnc->current->quant = RateControlGetQ(&pEnc->rate_control, 0);
# Line 661  Line 838 
838          pEnc->current->fcode = pEnc->mbParam.m_fcode;          pEnc->current->fcode = pEnc->mbParam.m_fcode;
839          pEnc->current->bcode = pEnc->mbParam.m_fcode;          pEnc->current->bcode = pEnc->mbParam.m_fcode;
840    
841          start_timer();  //$$$   start_timer();
842          if (image_input  //$$$   if (image_input
843                  (&pEnc->current->image, pEnc->mbParam.width, pEnc->mbParam.height,  //$$$           (&pEnc->current->image, pEnc->mbParam.width, pEnc->mbParam.height,
844                   pEnc->mbParam.edged_width, pFrame->image, pFrame->colorspace))  //$$$            pEnc->mbParam.edged_width, pFrame->image, pFrame->colorspace))
845                  return XVID_ERR_FORMAT;  //$$$           return XVID_ERR_FORMAT;
846          stop_conv_timer();  //$$$   stop_conv_timer();
847    
848  #ifdef _DEBUG  #ifdef _DEBUG_PSNR
849          image_copy(&pEnc->sOriginal, &pEnc->current->image,          image_copy(&pEnc->sOriginal, &pEnc->current->image,
850                             pEnc->mbParam.edged_width, pEnc->mbParam.height);                             pEnc->mbParam.edged_width, pEnc->mbParam.height);
851  #endif  #endif
852    
853          EMMS();          emms();
854    
855          /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%          /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
856           * Luminance masking           * Luminance masking
# Line 725  Line 902 
902                   * This will be coded as an Intra Frame                   * This will be coded as an Intra Frame
903                   */                   */
904    
905                  /* ToDo : Remove dprintf calls */                  DPRINTF("*** IFRAME bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
906                  /*                                  pEnc->bframenum_head, pEnc->bframenum_tail,
907                     dprintf("--- IFRAME ---");                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
                  */  
908    
909                  FrameCodeI(pEnc, &bs, &bits);                  FrameCodeI(pEnc, &bs, &bits);
910    
911                  pFrame->intra = 1;                  pFrame->intra = 1;
912                  pEnc->flush_bframes = 1;                  pEnc->flush_bframes = 1;
913    
914                    inc_frame_num(pEnc);
915    
916                    if (pEnc->packed) {
917                            BitstreamPad(&bs);
918                            input_valid = 0;
919                            goto ipvop_loop;
920                    }
921    
922                  /*                  /*
923                   * NB : sequences like "IIBB" decode fine with msfdam but,                   * NB : sequences like "IIBB" decode fine with msfdam but,
924                   *      go screwy with divx 5.00                   *      go screwy with divx 5.00
# Line 744  Line 928 
928                   * This will be coded as a Predicted Frame                   * This will be coded as a Predicted Frame
929                   */                   */
930    
931                  /* ToDo : Remove dprintf calls */                  DPRINTF("*** PFRAME bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
932                  /*                                  pEnc->bframenum_head, pEnc->bframenum_tail,
933                     dprintf("--- PFRAME ---");                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
                  */  
934    
935                  FrameCodeP(pEnc, &bs, &bits, 1, 0);                  FrameCodeP(pEnc, &bs, &bits, 1, 0);
936                  pFrame->intra = 0;                  pFrame->intra = 0;
937                  pEnc->flush_bframes = 1;                  pEnc->flush_bframes = 1;
938    
939                    inc_frame_num(pEnc);
940    
941                    if (pEnc->packed) {
942                            BitstreamPad(&bs);
943                            input_valid = 0;
944                            goto ipvop_loop;
945                    }
946    
947          } else {          } else {
948                  /*                  /*
949                   * This will be coded as a Bidirectional Frame                   * This will be coded as a Bidirectional Frame
950                   */                   */
951    
952                  /* ToDo : Remove dprintf calls */                  DPRINTF("*** BFRAME (store) bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
953                  /*                                  pEnc->bframenum_head, pEnc->bframenum_tail,
954                     dprintf("--- BFRAME (store) ---  head=%i tail=%i",                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
                    pEnc->bframenum_head,  
                    pEnc->bframenum_tail);  
                  */  
955    
956                  if (pFrame->bquant < 1) {                  if (pFrame->bquant < 1) {
957                          pEnc->current->quant =                          pEnc->current->quant =
# Line 780  Line 969 
969    
970                  pFrame->intra = 0;                  pFrame->intra = 0;
971                  pFrame->length = 0;                  pFrame->length = 0;
                 pFrame->input_consumed = 1;  
972    
973                  pEnc->mbParam.m_ticks += pEnc->mbParam.fincr;                  inc_frame_num(pEnc);
                 if (pEnc->mbParam.m_ticks > pEnc->mbParam.fbase) {  
                         pEnc->mbParam.m_seconds++;  
                         pEnc->mbParam.m_ticks = 0;  
                 }  
974    
975                  return XVID_ERR_OK;                  input_valid = 0;
976                    goto bvop_loop;
977          }          }
978    
979          BitstreamPad(&bs);          BitstreamPad(&bs);
# Line 802  Line 987 
987                  pResult->ublks = pEnc->sStat.ublks;                  pResult->ublks = pEnc->sStat.ublks;
988          }          }
989    
990          EMMS();          emms();
991    
992  #ifdef _DEBUG  #ifdef _DEBUG_PSNR
993          psnr =          psnr =
994                  image_psnr(&pEnc->sOriginal, &pEnc->current->image,                  image_psnr(&pEnc->sOriginal, &pEnc->current->image,
995                                     pEnc->mbParam.edged_width, pEnc->mbParam.width,                                     pEnc->mbParam.edged_width, pEnc->mbParam.width,
# Line 819  Line 1004 
1004                                                    pFrame->length, pFrame->intra);                                                    pFrame->length, pFrame->intra);
1005          }          }
1006    
         pEnc->iFrameNum++;  
         pEnc->mbParam.m_ticks += pEnc->mbParam.fincr;  
         if (pEnc->mbParam.m_ticks > pEnc->mbParam.fbase) {  
                 pEnc->mbParam.m_seconds++;  
                 pEnc->mbParam.m_ticks = 0;  
         }  
         pFrame->input_consumed = 1;  
1007    
1008          stop_global_timer();          stop_global_timer();
1009          write_timer();          write_timer();
1010    
1011          return XVID_ERR_OK;          return XVID_ERR_OK;
1012  }  }
1013  #else  
1014    #endif
1015    
1016    
1017    
1018  /*****************************************************************************  /*****************************************************************************
1019   * Frame encoder entry point for IP capable encoder   * "original" IP frame encoder entry point
1020     *
1021     * Returned values :
1022     *    - XVID_ERR_OK     - no errors
1023     *    - XVID_ERR_FORMAT - the image subsystem reported the image had a wrong
1024     *                        format
1025   ****************************************************************************/   ****************************************************************************/
1026    
1027  int  int
1028  encoder_encode(Encoder * pEnc,  encoder_encode(Encoder * pEnc,
1029                             XVID_ENC_FRAME * pFrame,                             XVID_ENC_FRAME * pFrame,
# Line 846  Line 1034 
1034          uint32_t bits;          uint32_t bits;
1035          uint16_t write_vol_header = 0;          uint16_t write_vol_header = 0;
1036    
1037  #ifdef _DEBUG  #ifdef _DEBUG_PSNR
1038          float psnr;          float psnr;
1039          uint8_t temp[128];          uint8_t temp[128];
1040  #endif  #endif
# Line 862  Line 1050 
1050    
1051          pEnc->current->global_flags = pFrame->general;          pEnc->current->global_flags = pFrame->general;
1052          pEnc->current->motion_flags = pFrame->motion;          pEnc->current->motion_flags = pFrame->motion;
1053    #ifdef BFRAMES
1054            pEnc->current->seconds = pEnc->mbParam.m_seconds;
1055            pEnc->current->ticks = pEnc->mbParam.m_ticks;
1056    #endif
1057          pEnc->mbParam.hint = &pFrame->hint;          pEnc->mbParam.hint = &pFrame->hint;
1058    
1059          start_timer();          start_timer();
# Line 871  Line 1063 
1063                  return XVID_ERR_FORMAT;                  return XVID_ERR_FORMAT;
1064          stop_conv_timer();          stop_conv_timer();
1065    
1066  #ifdef _DEBUG  #ifdef _DEBUG_PSNR
1067          image_copy(&pEnc->sOriginal, &pEnc->current->image,          image_copy(&pEnc->sOriginal, &pEnc->current->image,
1068                             pEnc->mbParam.edged_width, pEnc->mbParam.height);                             pEnc->mbParam.edged_width, pEnc->mbParam.height);
1069  #endif  #endif
1070    
1071          EMMS();          emms();
1072    
1073          BitstreamInit(&bs, pFrame->bitstream, 0);          BitstreamInit(&bs, pFrame->bitstream, 0);
1074    
# Line 975  Line 1167 
1167                  pResult->ublks = pEnc->sStat.ublks;                  pResult->ublks = pEnc->sStat.ublks;
1168          }          }
1169    
1170          EMMS();          emms();
1171    
1172          if (pFrame->quant == 0) {          if (pFrame->quant == 0) {
1173                  RateControlUpdate(&pEnc->rate_control, pEnc->current->quant,                  RateControlUpdate(&pEnc->rate_control, pEnc->current->quant,
1174                                                    pFrame->length, pFrame->intra);                                                    pFrame->length, pFrame->intra);
1175          }          }
1176  #ifdef _DEBUG  #ifdef _DEBUG_PSNR
1177          psnr =          psnr =
1178                  image_psnr(&pEnc->sOriginal, &pEnc->current->image,                  image_psnr(&pEnc->sOriginal, &pEnc->current->image,
1179                                     pEnc->mbParam.edged_width, pEnc->mbParam.width,                                     pEnc->mbParam.edged_width, pEnc->mbParam.width,
# Line 991  Line 1183 
1183          DEBUG(temp);          DEBUG(temp);
1184  #endif  #endif
1185    
1186    #ifdef BFRAMES
1187            inc_frame_num(pEnc);
1188    #else
1189          pEnc->iFrameNum++;          pEnc->iFrameNum++;
1190    #endif
1191    
1192    
1193          stop_global_timer();          stop_global_timer();
1194          write_timer();          write_timer();
1195    
1196          return XVID_ERR_OK;          return XVID_ERR_OK;
1197  }  }
 #endif  
1198    
1199    
1200  static __inline void  static __inline void
# Line 1246  Line 1442 
1442          pEnc->current->coding_type = I_VOP;          pEnc->current->coding_type = I_VOP;
1443    
1444          BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);          BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);
1445          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current);  #ifdef BFRAMES
1446    #define DIVX501B481P "DivX501b481p"
1447            if (pEnc->packed) {
1448                    BitstreamWriteUserData(bs, DIVX501B481P, strlen(DIVX501B481P));
1449            }
1450    #endif
1451            BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);
1452    
1453          *pBits = BitstreamPos(bs);          *pBits = BitstreamPos(bs);
1454    
# Line 1357  Line 1559 
1559          if (vol_header)          if (vol_header)
1560                  BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);                  BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);
1561    
1562          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);
1563    
1564          *pBits = BitstreamPos(bs);          *pBits = BitstreamPos(bs);
1565    
# Line 1515  Line 1717 
1717             } */             } */
1718    
1719          frame->coding_type = B_VOP;          frame->coding_type = B_VOP;
1720          BitstreamWriteVopHeader(bs, &pEnc->mbParam, frame);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, frame, 1);
1721    
1722          *pBits = BitstreamPos(bs);          *pBits = BitstreamPos(bs);
1723    

Legend:
Removed from v.195  
changed lines
  Added in v.233

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