[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.43, Fri Jun 14 13:21:35 2002 UTC revision 1.44, Thu Jun 20 14:05:57 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()
# Line 132  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 259  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 275  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 329  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 374  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 396  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 412  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 473  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 490  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 521  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 539  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++;
613                    pEnc->mbParam.m_ticks = 0;
614            }
615    
616    }
617    #endif
618    
619    
620    #ifdef BFRAMES
621    void queue_image(Encoder * pEnc, XVID_ENC_FRAME * pFrame)
622    {
623            if (pEnc->queue_size >= pEnc->mbParam.max_bframes)
624            {
625                    DPRINTF("FATAL: QUEUE FULL");
626                    return;
627            }
628    
629            DPRINTF("*** QUEUE bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
630                                    pEnc->bframenum_head, pEnc->bframenum_tail,
631                                    pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
632    
633    
634            start_timer();
635            if (image_input
636                    (&pEnc->queue[pEnc->queue_tail], pEnc->mbParam.width, pEnc->mbParam.height,
637                     pEnc->mbParam.edged_width, pFrame->image, pFrame->colorspace))
638                    return;
639            stop_conv_timer();
640    
641            pEnc->queue_size++;
642            pEnc->queue_tail =  (pEnc->queue_tail + 1) % pEnc->mbParam.max_bframes;
643    }
644    #endif
645    
646    
647    #ifdef BFRAMES
648  /*****************************************************************************  /*****************************************************************************
649   * 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.  
650   *   *
651   * Returned values :   * Returned values :
652   *    - XVID_ERR_OK     - no errors   *    - XVID_ERR_OK     - no errors
# Line 551  Line 654 
654   *                        format   *                        format
655   ****************************************************************************/   ****************************************************************************/
656    
   
 #ifdef BFRAMES  
 /*****************************************************************************  
  * Frame encoder entry point for IPB capable encoder  
  ****************************************************************************/  
657  int  int
658  encoder_encode(Encoder * pEnc,  encoder_encode_bframes(Encoder * pEnc,
659                             XVID_ENC_FRAME * pFrame,                             XVID_ENC_FRAME * pFrame,
660                             XVID_ENC_STATS * pResult)                             XVID_ENC_STATS * pResult)
661  {  {
# Line 565  Line 663 
663          Bitstream bs;          Bitstream bs;
664          uint32_t bits;          uint32_t bits;
665    
666  #ifdef _DEBUG          int input_valid = 1;
667    
668    #ifdef _DEBUG_PSNR
669          float psnr;          float psnr;
670          char temp[128];          char temp[128];
671  #endif  #endif
672    
673          ENC_CHECK(pEnc);          ENC_CHECK(pEnc);
674          ENC_CHECK(pFrame);          ENC_CHECK(pFrame);
675            ENC_CHECK(pFrame->image);
676    
677          start_global_timer();          start_global_timer();
678    
679          BitstreamInit(&bs, pFrame->bitstream, 0);          BitstreamInit(&bs, pFrame->bitstream, 0);
680    
681    ipvop_loop:
682    
683          /*          /*
684           * bframe "flush" code           * bframe "flush" code
685           */           */
# Line 591  Line 694 
694                           * frame as a pframe                           * frame as a pframe
695                           */                           */
696    
697                          /* ToDo : remove dprintf calls */                          DPRINTF("*** BFRAME (final frame) bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
698                          /*                                  pEnc->bframenum_head, pEnc->bframenum_tail,
699                             dprintf("--- PFRAME (final frame correction) --- ");                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
700                           */  
701                          pEnc->bframenum_tail--;                          pEnc->bframenum_tail--;
702                          SWAP(pEnc->current, pEnc->reference);                          SWAP(pEnc->current, pEnc->reference);
703    
# Line 604  Line 707 
707    
708                          BitstreamPad(&bs);                          BitstreamPad(&bs);
709                          pFrame->length = BitstreamLength(&bs);                          pFrame->length = BitstreamLength(&bs);
                         pFrame->input_consumed = 0;  
710                          pFrame->intra = 0;                          pFrame->intra = 0;
711    
712                          return XVID_ERR_OK;                          return XVID_ERR_OK;
713                  }                  }
714    
715                  /* ToDo : remove dprintf calls */  
716                  /*                  DPRINTF("*** BFRAME (flush) bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
717                     dprintf("--- BFRAME (flush) --- ");                                  pEnc->bframenum_head, pEnc->bframenum_tail,
718                   */                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
719    
720                  FrameCodeB(pEnc, pEnc->bframes[pEnc->bframenum_head], &bs, &bits);                  FrameCodeB(pEnc, pEnc->bframes[pEnc->bframenum_head], &bs, &bits);
721                  pEnc->bframenum_head++;                  pEnc->bframenum_head++;
722    
   
723                  BitstreamPad(&bs);                  BitstreamPad(&bs);
724                  pFrame->length = BitstreamLength(&bs);                  pFrame->length = BitstreamLength(&bs);
                 pFrame->input_consumed = 0;  
725                  pFrame->intra = 0;                  pFrame->intra = 0;
726    
727                    if (input_valid)
728                            queue_image(pEnc, pFrame);
729    
730                  return XVID_ERR_OK;                  return XVID_ERR_OK;
731          }          }
732    
733          if (pFrame->image == NULL) {          if (pEnc->bframenum_head > 0) {
734                  pFrame->length = 0;                  pEnc->bframenum_head = pEnc->bframenum_tail = 0;
735                  pFrame->input_consumed = 1;  
736                    if (pEnc->packed) {
737    
738                            DPRINTF("*** EMPTY bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
739                                    pEnc->bframenum_head, pEnc->bframenum_tail,
740                                    pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
741    
742    
743                            BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0);
744                            BitstreamPad(&bs);
745                            BitstreamPutBits(&bs, 0x7f, 8);
746    
747                            pFrame->length = BitstreamLength(&bs);
748                  pFrame->intra = 0;                  pFrame->intra = 0;
749    
750                            if (input_valid)
751                                    queue_image(pEnc, pFrame);
752    
753                  return XVID_ERR_OK;                  return XVID_ERR_OK;
754          }          }
755            }
756    
757          if (pEnc->bframenum_head > 0) {  
758                  pEnc->bframenum_head = pEnc->bframenum_tail = 0;  bvop_loop:
759    
760            if (input_valid) {
761    
762                    SWAP(pEnc->current, pEnc->reference);
763    
764                    start_timer();
765                    if (image_input
766                            (&pEnc->current->image, pEnc->mbParam.width, pEnc->mbParam.height,
767                            pEnc->mbParam.edged_width, pFrame->image, pFrame->colorspace))
768                            return XVID_ERR_FORMAT;
769                    stop_conv_timer();
770    
771                    // queue input frame, and dequue next image
772                    if (pEnc->queue_size > 0)
773                    {
774                            image_swap(&pEnc->current->image, &pEnc->queue[pEnc->queue_tail]);
775                            if (pEnc->queue_head != pEnc->queue_tail)
776                            {
777                                    image_swap(&pEnc->current->image, &pEnc->queue[pEnc->queue_head]);
778                            }
779                            pEnc->queue_head =  (pEnc->queue_head + 1) % pEnc->mbParam.max_bframes;
780                            pEnc->queue_tail =  (pEnc->queue_tail + 1) % pEnc->mbParam.max_bframes;
781                    }
782    
783            } else if (pEnc->queue_size > 0) {
784    
785                    SWAP(pEnc->current, pEnc->reference);
786    
787                    image_swap(&pEnc->current->image, &pEnc->queue[pEnc->queue_head]);
788                    pEnc->queue_head =  (pEnc->queue_head + 1) % pEnc->mbParam.max_bframes;
789                    pEnc->queue_size--;
790    
791            } else if (BitstreamPos(&bs) == 0) {
792    
793                    DPRINTF("*** SKIP bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
794                                    pEnc->bframenum_head, pEnc->bframenum_tail,
795                                    pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
796    
797    
798                    pFrame->intra = 0;
799    
800                    BitstreamPutBits(&bs, 0x7f, 8);
801                    BitstreamPad(&bs);
802                    pFrame->length = BitstreamLength(&bs);
803    
804                    return XVID_ERR_OK;
805    
806            } else {
807    
808                    pFrame->length = BitstreamLength(&bs);
809                    return XVID_ERR_OK;
810          }          }
811    
812          pEnc->flush_bframes = 0;          pEnc->flush_bframes = 0;
# Line 645  Line 816 
816           * comment style :-)           * comment style :-)
817           * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */           * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
818    
819          SWAP(pEnc->current, pEnc->reference);  //$$    SWAP(pEnc->current, pEnc->reference);
820    
821          emms();          emms();
822    
# Line 668  Line 839 
839          pEnc->current->fcode = pEnc->mbParam.m_fcode;          pEnc->current->fcode = pEnc->mbParam.m_fcode;
840          pEnc->current->bcode = pEnc->mbParam.m_fcode;          pEnc->current->bcode = pEnc->mbParam.m_fcode;
841    
842          start_timer();  //$$$   start_timer();
843          if (image_input  //$$$   if (image_input
844                  (&pEnc->current->image, pEnc->mbParam.width, pEnc->mbParam.height,  //$$$           (&pEnc->current->image, pEnc->mbParam.width, pEnc->mbParam.height,
845                   pEnc->mbParam.edged_width, pFrame->image, pFrame->colorspace))  //$$$            pEnc->mbParam.edged_width, pFrame->image, pFrame->colorspace))
846                  return XVID_ERR_FORMAT;  //$$$           return XVID_ERR_FORMAT;
847          stop_conv_timer();  //$$$   stop_conv_timer();
848    
849  #ifdef _DEBUG  #ifdef _DEBUG_PSNR
850          image_copy(&pEnc->sOriginal, &pEnc->current->image,          image_copy(&pEnc->sOriginal, &pEnc->current->image,
851                             pEnc->mbParam.edged_width, pEnc->mbParam.height);                             pEnc->mbParam.edged_width, pEnc->mbParam.height);
852  #endif  #endif
# Line 732  Line 903 
903                   * This will be coded as an Intra Frame                   * This will be coded as an Intra Frame
904                   */                   */
905    
906                  /* ToDo : Remove dprintf calls */                  DPRINTF("*** IFRAME bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
907                  /*                                  pEnc->bframenum_head, pEnc->bframenum_tail,
908                     dprintf("--- IFRAME ---");                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
                  */  
909    
910                  FrameCodeI(pEnc, &bs, &bits);                  FrameCodeI(pEnc, &bs, &bits);
911    
912                  pFrame->intra = 1;                  pFrame->intra = 1;
913                  pEnc->flush_bframes = 1;                  pEnc->flush_bframes = 1;
914    
915                    inc_frame_num(pEnc);
916    
917                    if (pEnc->packed) {
918                            BitstreamPad(&bs);
919                            input_valid = 0;
920                            goto ipvop_loop;
921                    }
922    
923                  /*                  /*
924                   * NB : sequences like "IIBB" decode fine with msfdam but,                   * NB : sequences like "IIBB" decode fine with msfdam but,
925                   *      go screwy with divx 5.00                   *      go screwy with divx 5.00
# Line 751  Line 929 
929                   * This will be coded as a Predicted Frame                   * This will be coded as a Predicted Frame
930                   */                   */
931    
932                  /* ToDo : Remove dprintf calls */                  DPRINTF("*** PFRAME bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
933                  /*                                  pEnc->bframenum_head, pEnc->bframenum_tail,
934                     dprintf("--- PFRAME ---");                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
                  */  
935    
936                  FrameCodeP(pEnc, &bs, &bits, 1, 0);                  FrameCodeP(pEnc, &bs, &bits, 1, 0);
937                  pFrame->intra = 0;                  pFrame->intra = 0;
938                  pEnc->flush_bframes = 1;                  pEnc->flush_bframes = 1;
939    
940                    inc_frame_num(pEnc);
941    
942                    if (pEnc->packed) {
943                            BitstreamPad(&bs);
944                            input_valid = 0;
945                            goto ipvop_loop;
946                    }
947    
948          } else {          } else {
949                  /*                  /*
950                   * This will be coded as a Bidirectional Frame                   * This will be coded as a Bidirectional Frame
951                   */                   */
952    
953                  /* ToDo : Remove dprintf calls */                  DPRINTF("*** BFRAME (store) bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
954                  /*                                  pEnc->bframenum_head, pEnc->bframenum_tail,
955                     dprintf("--- BFRAME (store) ---  head=%i tail=%i",                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
                    pEnc->bframenum_head,  
                    pEnc->bframenum_tail);  
                  */  
956    
957                  if (pFrame->bquant < 1) {                  if (pFrame->bquant < 1) {
958                          pEnc->current->quant =                          pEnc->current->quant =
# Line 787  Line 970 
970    
971                  pFrame->intra = 0;                  pFrame->intra = 0;
972                  pFrame->length = 0;                  pFrame->length = 0;
                 pFrame->input_consumed = 1;  
973    
974                  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;  
                 }  
975    
976                  return XVID_ERR_OK;                  input_valid = 0;
977                    goto bvop_loop;
978          }          }
979    
980          BitstreamPad(&bs);          BitstreamPad(&bs);
# Line 811  Line 990 
990    
991          emms();          emms();
992    
993  #ifdef _DEBUG  #ifdef _DEBUG_PSNR
994          psnr =          psnr =
995                  image_psnr(&pEnc->sOriginal, &pEnc->current->image,                  image_psnr(&pEnc->sOriginal, &pEnc->current->image,
996                                     pEnc->mbParam.edged_width, pEnc->mbParam.width,                                     pEnc->mbParam.edged_width, pEnc->mbParam.width,
# Line 826  Line 1005 
1005                                                    pFrame->length, pFrame->intra);                                                    pFrame->length, pFrame->intra);
1006          }          }
1007    
         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;  
1008    
1009          stop_global_timer();          stop_global_timer();
1010          write_timer();          write_timer();
1011    
1012          return XVID_ERR_OK;          return XVID_ERR_OK;
1013  }  }
1014  #else  
1015    #endif
1016    
1017    
1018    
1019  /*****************************************************************************  /*****************************************************************************
1020   * Frame encoder entry point for IP capable encoder   * "original" IP frame encoder entry point
1021     *
1022     * Returned values :
1023     *    - XVID_ERR_OK     - no errors
1024     *    - XVID_ERR_FORMAT - the image subsystem reported the image had a wrong
1025     *                        format
1026   ****************************************************************************/   ****************************************************************************/
1027    
1028  int  int
1029  encoder_encode(Encoder * pEnc,  encoder_encode(Encoder * pEnc,
1030                             XVID_ENC_FRAME * pFrame,                             XVID_ENC_FRAME * pFrame,
# Line 853  Line 1035 
1035          uint32_t bits;          uint32_t bits;
1036          uint16_t write_vol_header = 0;          uint16_t write_vol_header = 0;
1037    
1038  #ifdef _DEBUG  #ifdef _DEBUG_PSNR
1039          float psnr;          float psnr;
1040          uint8_t temp[128];          uint8_t temp[128];
1041  #endif  #endif
# Line 869  Line 1051 
1051    
1052          pEnc->current->global_flags = pFrame->general;          pEnc->current->global_flags = pFrame->general;
1053          pEnc->current->motion_flags = pFrame->motion;          pEnc->current->motion_flags = pFrame->motion;
1054    #ifdef BFRAMES
1055            pEnc->current->seconds = pEnc->mbParam.m_seconds;
1056            pEnc->current->ticks = pEnc->mbParam.m_ticks;
1057    #endif
1058          pEnc->mbParam.hint = &pFrame->hint;          pEnc->mbParam.hint = &pFrame->hint;
1059    
1060          start_timer();          start_timer();
# Line 878  Line 1064 
1064                  return XVID_ERR_FORMAT;                  return XVID_ERR_FORMAT;
1065          stop_conv_timer();          stop_conv_timer();
1066    
1067  #ifdef _DEBUG  #ifdef _DEBUG_PSNR
1068          image_copy(&pEnc->sOriginal, &pEnc->current->image,          image_copy(&pEnc->sOriginal, &pEnc->current->image,
1069                             pEnc->mbParam.edged_width, pEnc->mbParam.height);                             pEnc->mbParam.edged_width, pEnc->mbParam.height);
1070  #endif  #endif
# Line 988  Line 1174 
1174                  RateControlUpdate(&pEnc->rate_control, pEnc->current->quant,                  RateControlUpdate(&pEnc->rate_control, pEnc->current->quant,
1175                                                    pFrame->length, pFrame->intra);                                                    pFrame->length, pFrame->intra);
1176          }          }
1177  #ifdef _DEBUG  #ifdef _DEBUG_PSNR
1178          psnr =          psnr =
1179                  image_psnr(&pEnc->sOriginal, &pEnc->current->image,                  image_psnr(&pEnc->sOriginal, &pEnc->current->image,
1180                                     pEnc->mbParam.edged_width, pEnc->mbParam.width,                                     pEnc->mbParam.edged_width, pEnc->mbParam.width,
# Line 998  Line 1184 
1184          DEBUG(temp);          DEBUG(temp);
1185  #endif  #endif
1186    
1187    #ifdef BFRAMES
1188            inc_frame_num(pEnc);
1189    #else
1190          pEnc->iFrameNum++;          pEnc->iFrameNum++;
1191    #endif
1192    
1193    
1194          stop_global_timer();          stop_global_timer();
1195          write_timer();          write_timer();
1196    
1197          return XVID_ERR_OK;          return XVID_ERR_OK;
1198  }  }
 #endif  
1199    
1200    
1201  static __inline void  static __inline void
# Line 1253  Line 1443 
1443          pEnc->current->coding_type = I_VOP;          pEnc->current->coding_type = I_VOP;
1444    
1445          BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);          BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);
1446          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current);  #ifdef BFRAMES
1447    #define DIVX501B481P "DivX501b481p"
1448            if (pEnc->packed) {
1449                    BitstreamWriteUserData(bs, DIVX501B481P, strlen(DIVX501B481P));
1450            }
1451    #endif
1452            BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);
1453    
1454          *pBits = BitstreamPos(bs);          *pBits = BitstreamPos(bs);
1455    
# Line 1364  Line 1560 
1560          if (vol_header)          if (vol_header)
1561                  BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);                  BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);
1562    
1563          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);
1564    
1565          *pBits = BitstreamPos(bs);          *pBits = BitstreamPos(bs);
1566    
# Line 1522  Line 1718 
1718             } */             } */
1719    
1720          frame->coding_type = B_VOP;          frame->coding_type = B_VOP;
1721          BitstreamWriteVopHeader(bs, &pEnc->mbParam, frame);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, frame, 1);
1722    
1723          *pBits = BitstreamPos(bs);          *pBits = BitstreamPos(bs);
1724    

Legend:
Removed from v.1.43  
changed lines
  Added in v.1.44

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