[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 208, Fri Jun 14 13:21:35 2002 UTC revision 236, Sun Jun 23 19:48:06 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.43 2002-06-14 13:21:35 Isibaar Exp $   *  $Id: encoder.c,v 1.47 2002-06-23 19:48:06 edgomez Exp $
41   *   *
42   ****************************************************************************/   ****************************************************************************/
43    
# 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->global = pParam->global;
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            pEnc->m_framenum = 0;
412  #endif  #endif
413    
414          pParam->handle = (void *) pEnc;          pParam->handle = (void *) pEnc;
# Line 396  Line 429 
429           * We handle all XVID_ERR_MEMORY here, this makes the code lighter           * We handle all XVID_ERR_MEMORY here, this makes the code lighter
430           */           */
431  #ifdef BFRAMES  #ifdef BFRAMES
432      xvid_err_memory5:
433    
434    
435            if (pEnc->mbParam.max_bframes > 0) {
436    
437                    for (i = 0; i < pEnc->mbParam.max_bframes; i++) {
438                            image_destroy(&pEnc->queue[i], pEnc->mbParam.edged_width,
439                                                      pEnc->mbParam.edged_height);
440                    }
441                    xvid_free(pEnc->queue);
442            }
443    
444    xvid_err_memory4:    xvid_err_memory4:
445    
446            if (pEnc->mbParam.max_bframes > 0) {
447    
448          for (i = 0; i < pEnc->mbParam.max_bframes; i++) {          for (i = 0; i < pEnc->mbParam.max_bframes; i++) {
449    
450                  if (pEnc->bframes[i] == NULL)                  if (pEnc->bframes[i] == NULL)
# Line 412  Line 460 
460          }          }
461    
462          xvid_free(pEnc->bframes);          xvid_free(pEnc->bframes);
463            }
464    
465  #endif  #endif
466    
467    xvid_err_memory3:    xvid_err_memory3:
468  #ifdef _DEBUG  #ifdef _DEBUG_PSNR
469          image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width,          image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width,
470                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
471  #endif  #endif
# Line 473  Line 522 
522  int  int
523  encoder_destroy(Encoder * pEnc)  encoder_destroy(Encoder * pEnc)
524  {  {
525    #ifdef BFRAMES
526            int i;
527    #endif
528    
529          ENC_CHECK(pEnc);          ENC_CHECK(pEnc);
530    
531          /* B Frames specific */          /* B Frames specific */
532  #ifdef BFRAMES  #ifdef BFRAMES
533          int i;          if (pEnc->mbParam.max_bframes > 0) {
534    
535                    for (i = 0; i < pEnc->mbParam.max_bframes; i++) {
536    
537                            image_destroy(&pEnc->queue[i], pEnc->mbParam.edged_width,
538                                              pEnc->mbParam.edged_height);
539                    }
540                    xvid_free(pEnc->queue);
541            }
542    
543    
544            if (pEnc->mbParam.max_bframes > 0) {
545    
546          for (i = 0; i < pEnc->mbParam.max_bframes; i++) {          for (i = 0; i < pEnc->mbParam.max_bframes; i++) {
547    
# Line 490  Line 554 
554                  xvid_free(pEnc->bframes[i]->mbs);                  xvid_free(pEnc->bframes[i]->mbs);
555    
556                  xvid_free(pEnc->bframes[i]);                  xvid_free(pEnc->bframes[i]);
   
557          }          }
558    
559          xvid_free(pEnc->bframes);          xvid_free(pEnc->bframes);
560    
561            }
562  #endif  #endif
563    
564          /* All images, reference, current etc ... */          /* All images, reference, current etc ... */
# Line 521  Line 585 
585          image_destroy(&pEnc->f_refhv, pEnc->mbParam.edged_width,          image_destroy(&pEnc->f_refhv, pEnc->mbParam.edged_width,
586                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
587  #endif  #endif
588  #ifdef _DEBUG  #ifdef _DEBUG_PSNR
589          image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width,          image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width,
590                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
591  #endif  #endif
# Line 539  Line 603 
603          return XVID_ERR_OK;          return XVID_ERR_OK;
604  }  }
605    
606    
607    #ifdef BFRAMES
608    void inc_frame_num(Encoder * pEnc)
609    {
610            pEnc->iFrameNum++;
611            pEnc->mbParam.m_ticks += pEnc->mbParam.fincr;
612    
613            pEnc->mbParam.m_seconds = pEnc->mbParam.m_ticks / pEnc->mbParam.fbase;
614            pEnc->mbParam.m_ticks = pEnc->mbParam.m_ticks % pEnc->mbParam.fbase;
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 551  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 565  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 591  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 604  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->global & XVID_GLOBAL_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 645  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    
# Line 668  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            if ((pEnc->global & XVID_GLOBAL_DEBUG)) {
856                    image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 5,
857                            "%i  if:%i  st:%i:%i", pEnc->m_framenum++, pEnc->iFrameNum, pEnc->current->seconds, pEnc->current->ticks);
858            }
859    
860    
861          /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%          /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
862           * Luminance masking           * Luminance masking
863           * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */           * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
# Line 732  Line 908 
908                   * This will be coded as an Intra Frame                   * This will be coded as an Intra Frame
909                   */                   */
910    
911                  /* ToDo : Remove dprintf calls */                  DPRINTF("*** IFRAME bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
912                  /*                                  pEnc->bframenum_head, pEnc->bframenum_tail,
913                     dprintf("--- IFRAME ---");                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
914                   */  
915                    if ((pEnc->global & XVID_GLOBAL_DEBUG)) {
916                            image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "IVOP");
917                    }
918    
919                  FrameCodeI(pEnc, &bs, &bits);                  FrameCodeI(pEnc, &bs, &bits);
920    
921                  pFrame->intra = 1;                  pFrame->intra = 1;
922                  pEnc->flush_bframes = 1;                  pEnc->flush_bframes = 1;
923    
924                    inc_frame_num(pEnc);
925    
926                    if ((pEnc->global & XVID_GLOBAL_PACKED)) {
927                            BitstreamPad(&bs);
928                            input_valid = 0;
929                            goto ipvop_loop;
930                    }
931    
932                  /*                  /*
933                   * NB : sequences like "IIBB" decode fine with msfdam but,                   * NB : sequences like "IIBB" decode fine with msfdam but,
934                   *      go screwy with divx 5.00                   *      go screwy with divx 5.00
# Line 751  Line 938 
938                   * This will be coded as a Predicted Frame                   * This will be coded as a Predicted Frame
939                   */                   */
940    
941                  /* ToDo : Remove dprintf calls */                  DPRINTF("*** PFRAME bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
942                  /*                                  pEnc->bframenum_head, pEnc->bframenum_tail,
943                     dprintf("--- PFRAME ---");                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
944                   */  
945                    if ((pEnc->global & XVID_GLOBAL_DEBUG)) {
946                            image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "PVOP");
947                    }
948    
949                  FrameCodeP(pEnc, &bs, &bits, 1, 0);                  FrameCodeP(pEnc, &bs, &bits, 1, 0);
950                  pFrame->intra = 0;                  pFrame->intra = 0;
951                  pEnc->flush_bframes = 1;                  pEnc->flush_bframes = 1;
952    
953                    inc_frame_num(pEnc);
954    
955                    if ((pEnc->global & XVID_GLOBAL_PACKED)) {
956                            BitstreamPad(&bs);
957                            input_valid = 0;
958                            goto ipvop_loop;
959                    }
960    
961          } else {          } else {
962                  /*                  /*
963                   * This will be coded as a Bidirectional Frame                   * This will be coded as a Bidirectional Frame
964                   */                   */
965    
966                  /* ToDo : Remove dprintf calls */                  DPRINTF("*** BFRAME (store) bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
967                  /*                                  pEnc->bframenum_head, pEnc->bframenum_tail,
968                     dprintf("--- BFRAME (store) ---  head=%i tail=%i",                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
969                     pEnc->bframenum_head,  
970                     pEnc->bframenum_tail);                  if ((pEnc->global & XVID_GLOBAL_DEBUG)) {
971                   */                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "BVOP");
972                    }
973    
974                  if (pFrame->bquant < 1) {                  if (pFrame->bquant < 1) {
975                          pEnc->current->quant =                          pEnc->current->quant =
# Line 787  Line 987 
987    
988                  pFrame->intra = 0;                  pFrame->intra = 0;
989                  pFrame->length = 0;                  pFrame->length = 0;
                 pFrame->input_consumed = 1;  
990    
991                  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;  
                 }  
992    
993                  return XVID_ERR_OK;                  input_valid = 0;
994                    goto bvop_loop;
995          }          }
996    
997          BitstreamPad(&bs);          BitstreamPad(&bs);
# Line 811  Line 1007 
1007    
1008          emms();          emms();
1009    
1010  #ifdef _DEBUG  #ifdef _DEBUG_PSNR
1011          psnr =          psnr =
1012                  image_psnr(&pEnc->sOriginal, &pEnc->current->image,                  image_psnr(&pEnc->sOriginal, &pEnc->current->image,
1013                                     pEnc->mbParam.edged_width, pEnc->mbParam.width,                                     pEnc->mbParam.edged_width, pEnc->mbParam.width,
# Line 826  Line 1022 
1022                                                    pFrame->length, pFrame->intra);                                                    pFrame->length, pFrame->intra);
1023          }          }
1024    
         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;  
1025    
1026          stop_global_timer();          stop_global_timer();
1027          write_timer();          write_timer();
1028    
1029          return XVID_ERR_OK;          return XVID_ERR_OK;
1030  }  }
1031  #else  
1032    #endif
1033    
1034    
1035    
1036  /*****************************************************************************  /*****************************************************************************
1037   * Frame encoder entry point for IP capable encoder   * "original" IP frame encoder entry point
1038     *
1039     * Returned values :
1040     *    - XVID_ERR_OK     - no errors
1041     *    - XVID_ERR_FORMAT - the image subsystem reported the image had a wrong
1042     *                        format
1043   ****************************************************************************/   ****************************************************************************/
1044    
1045  int  int
1046  encoder_encode(Encoder * pEnc,  encoder_encode(Encoder * pEnc,
1047                             XVID_ENC_FRAME * pFrame,                             XVID_ENC_FRAME * pFrame,
# Line 853  Line 1052 
1052          uint32_t bits;          uint32_t bits;
1053          uint16_t write_vol_header = 0;          uint16_t write_vol_header = 0;
1054    
1055  #ifdef _DEBUG  #ifdef _DEBUG_PSNR
1056          float psnr;          float psnr;
1057          uint8_t temp[128];          uint8_t temp[128];
1058  #endif  #endif
# Line 869  Line 1068 
1068    
1069          pEnc->current->global_flags = pFrame->general;          pEnc->current->global_flags = pFrame->general;
1070          pEnc->current->motion_flags = pFrame->motion;          pEnc->current->motion_flags = pFrame->motion;
1071    #ifdef BFRAMES
1072            pEnc->current->seconds = pEnc->mbParam.m_seconds;
1073            pEnc->current->ticks = pEnc->mbParam.m_ticks;
1074    #endif
1075          pEnc->mbParam.hint = &pFrame->hint;          pEnc->mbParam.hint = &pFrame->hint;
1076    
1077          start_timer();          start_timer();
# Line 878  Line 1081 
1081                  return XVID_ERR_FORMAT;                  return XVID_ERR_FORMAT;
1082          stop_conv_timer();          stop_conv_timer();
1083    
1084  #ifdef _DEBUG  #ifdef _DEBUG_PSNR
1085          image_copy(&pEnc->sOriginal, &pEnc->current->image,          image_copy(&pEnc->sOriginal, &pEnc->current->image,
1086                             pEnc->mbParam.edged_width, pEnc->mbParam.height);                             pEnc->mbParam.edged_width, pEnc->mbParam.height);
1087  #endif  #endif
# Line 988  Line 1191 
1191                  RateControlUpdate(&pEnc->rate_control, pEnc->current->quant,                  RateControlUpdate(&pEnc->rate_control, pEnc->current->quant,
1192                                                    pFrame->length, pFrame->intra);                                                    pFrame->length, pFrame->intra);
1193          }          }
1194  #ifdef _DEBUG  #ifdef _DEBUG_PSNR
1195          psnr =          psnr =
1196                  image_psnr(&pEnc->sOriginal, &pEnc->current->image,                  image_psnr(&pEnc->sOriginal, &pEnc->current->image,
1197                                     pEnc->mbParam.edged_width, pEnc->mbParam.width,                                     pEnc->mbParam.edged_width, pEnc->mbParam.width,
# Line 998  Line 1201 
1201          DEBUG(temp);          DEBUG(temp);
1202  #endif  #endif
1203    
1204    #ifdef BFRAMES
1205            inc_frame_num(pEnc);
1206    #else
1207          pEnc->iFrameNum++;          pEnc->iFrameNum++;
1208    #endif
1209    
1210    
1211          stop_global_timer();          stop_global_timer();
1212          write_timer();          write_timer();
1213    
1214          return XVID_ERR_OK;          return XVID_ERR_OK;
1215  }  }
 #endif  
1216    
1217    
1218  static __inline void  static __inline void
# Line 1253  Line 1460 
1460          pEnc->current->coding_type = I_VOP;          pEnc->current->coding_type = I_VOP;
1461    
1462          BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);          BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);
1463          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current);  #ifdef BFRAMES
1464    #define DIVX501B481P "DivX501b481p"
1465            if ((pEnc->global & XVID_GLOBAL_PACKED)) {
1466                    BitstreamWriteUserData(bs, DIVX501B481P, strlen(DIVX501B481P));
1467            }
1468    #endif
1469            BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);
1470    
1471          *pBits = BitstreamPos(bs);          *pBits = BitstreamPos(bs);
1472    
# Line 1364  Line 1577 
1577          if (vol_header)          if (vol_header)
1578                  BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);                  BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);
1579    
1580          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);
1581    
1582          *pBits = BitstreamPos(bs);          *pBits = BitstreamPos(bs);
1583    
# Line 1522  Line 1735 
1735             } */             } */
1736    
1737          frame->coding_type = B_VOP;          frame->coding_type = B_VOP;
1738          BitstreamWriteVopHeader(bs, &pEnc->mbParam, frame);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, frame, 1);
1739    
1740          *pBits = BitstreamPos(bs);          *pBits = BitstreamPos(bs);
1741    
# Line 1585  Line 1798 
1798                                  backward.x = mb->b_mvs[0].x;                                  backward.x = mb->b_mvs[0].x;
1799                                  backward.y = mb->b_mvs[0].y;                                  backward.y = mb->b_mvs[0].y;
1800                          }                          }
1801  //          printf("[%i %i] M=%i CBP=%i MVX=%i MVY=%i %i,%i  %i,%i\n", x, y, pMB->mode, pMB->cbp, pMB->mvs[0].x, bmb->pmvs[0].x, bmb->pmvs[0].y, forward.x, forward.y);  //                      DPRINTF("%05i : [%i %i] M=%i CBP=%i MVS=%i,%i forward=%i,%i", pEnc->m_framenum, x, y, mb->mode, mb->cbp, mb->mvs[0].x, mb->mvs[0].y, forward.x, forward.y);
1802    
1803                          start_timer();                          start_timer();
1804                          MBCodingBVOP(mb, qcoeff, frame->fcode, frame->bcode, bs,                          MBCodingBVOP(mb, qcoeff, frame->fcode, frame->bcode, bs,

Legend:
Removed from v.208  
changed lines
  Added in v.236

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