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

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

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

trunk/xvidcore/src/encoder.c revision 195, Wed Jun 12 20:38:41 2002 UTC branches/dev-api-3/xvidcore/src/encoder.c revision 579, Sat Oct 5 21:37:44 2002 UTC
# Line 32  Line 32 
32   *   *
33   *  History   *  History
34   *   *
35     *  10.07.2002  added BFRAMES_DEC_DEBUG support
36     *              MinChen <chenm001@163.com>
37     *  20.06.2002 bframe patch
38   *  08.05.2002 fix some problem in DEBUG mode;   *  08.05.2002 fix some problem in DEBUG mode;
39   *             MinChen <chenm001@163.com>   *             MinChen <chenm001@163.com>
40   *  14.04.2002 added FrameCodeB()   *  14.04.2002 added FrameCodeB()
41   *   *
42   *  $Id: encoder.c,v 1.41 2002-06-12 20:38:40 edgomez Exp $   *  $Id: encoder.c,v 1.76.2.12 2002-10-05 21:36:35 Isibaar Exp $
43   *   *
44   ****************************************************************************/   ****************************************************************************/
45    
46    
47  #include <stdlib.h>  #include <stdlib.h>
48  #include <stdio.h>  #include <stdio.h>
49  #include <math.h>  #include <math.h>
50    #include <string.h>
51    
52  #include "encoder.h"  #include "encoder.h"
53  #include "prediction/mbprediction.h"  #include "prediction/mbprediction.h"
54  #include "global.h"  #include "global.h"
55  #include "utils/timer.h"  #include "utils/timer.h"
56  #include "image/image.h"  #include "image/image.h"
57    #ifdef BFRAMES
58    #include "image/font.h"
59    #include "motion/sad.h"
60    #endif
61  #include "motion/motion.h"  #include "motion/motion.h"
62  #include "bitstream/cbp.h"  #include "bitstream/cbp.h"
63  #include "utils/mbfunctions.h"  #include "utils/mbfunctions.h"
# Line 82  Line 91 
91                                            bool force_inter,                                            bool force_inter,
92                                            bool vol_header);                                            bool vol_header);
93    
 #ifdef BFRAMES  
94  static void FrameCodeB(Encoder * pEnc,  static void FrameCodeB(Encoder * pEnc,
95                                             FRAMEINFO * frame,                                             FRAMEINFO * frame,
96                                             Bitstream * bs,                                             Bitstream * bs,
97                                             uint32_t * pBits);                                             uint32_t * pBits);
 #endif  
98    
99  /*****************************************************************************  /*****************************************************************************
100   * Local data   * Local data
# Line 131  Line 138 
138  encoder_create(XVID_ENC_PARAM * pParam)  encoder_create(XVID_ENC_PARAM * pParam)
139  {  {
140          Encoder *pEnc;          Encoder *pEnc;
141          uint32_t i;          int i;
142    
143          pParam->handle = NULL;          pParam->handle = NULL;
144    
# Line 199  Line 206 
206    
207          /* 1 keyframe each 10 seconds */          /* 1 keyframe each 10 seconds */
208    
209          if (pParam->max_key_interval == 0)          if (pParam->max_key_interval <= 0)
210                  pParam->max_key_interval = 10 * pParam->fincr / pParam->fbase;                  pParam->max_key_interval = 10 * pParam->fincr / pParam->fbase;
211    
   
212          pEnc = (Encoder *) xvid_malloc(sizeof(Encoder), CACHE_LINE);          pEnc = (Encoder *) xvid_malloc(sizeof(Encoder), CACHE_LINE);
213          if (pEnc == NULL)          if (pEnc == NULL)
214                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
215    
216            /* Zero the Encoder Structure */
217    
218            memset(pEnc, 0, sizeof(Encoder));
219    
220          /* Fill members of Encoder structure */          /* Fill members of Encoder structure */
221    
222          pEnc->mbParam.width = pParam->width;          pEnc->mbParam.width = pParam->width;
# Line 221  Line 231 
231          pEnc->mbParam.fbase = pParam->fbase;          pEnc->mbParam.fbase = pParam->fbase;
232          pEnc->mbParam.fincr = pParam->fincr;          pEnc->mbParam.fincr = pParam->fincr;
233    
234            pEnc->mbParam.m_quant_type = H263_QUANT;
235    
236          pEnc->sStat.fMvPrevSigma = -1;          pEnc->sStat.fMvPrevSigma = -1;
237    
238          /* Fill rate control parameters */          /* Fill rate control parameters */
# Line 252  Line 264 
264    
265          /* try to allocate image memory */          /* try to allocate image memory */
266    
267  #ifdef _DEBUG  #ifdef _DEBUG_PSNR
268          image_null(&pEnc->sOriginal);          image_null(&pEnc->sOriginal);
269  #endif  #endif
270  #ifdef BFRAMES  
271          image_null(&pEnc->f_refh);          image_null(&pEnc->f_refh);
272          image_null(&pEnc->f_refv);          image_null(&pEnc->f_refv);
273          image_null(&pEnc->f_refhv);          image_null(&pEnc->f_refhv);
274  #endif  
275          image_null(&pEnc->current->image);          image_null(&pEnc->current->image);
276          image_null(&pEnc->reference->image);          image_null(&pEnc->reference->image);
277          image_null(&pEnc->vInterH);          image_null(&pEnc->vInterH);
# Line 268  Line 280 
280          image_null(&pEnc->vInterHV);          image_null(&pEnc->vInterHV);
281          image_null(&pEnc->vInterHVf);          image_null(&pEnc->vInterHVf);
282    
283  #ifdef _DEBUG  #ifdef _DEBUG_PSNR
284          if (image_create          if (image_create
285                  (&pEnc->sOriginal, pEnc->mbParam.edged_width,                  (&pEnc->sOriginal, pEnc->mbParam.edged_width,
286                   pEnc->mbParam.edged_height) < 0)                   pEnc->mbParam.edged_height) < 0)
287                  goto xvid_err_memory3;                  goto xvid_err_memory3;
288  #endif  #endif
289  #ifdef BFRAMES  
290          if (image_create          if (image_create
291                  (&pEnc->f_refh, pEnc->mbParam.edged_width,                  (&pEnc->f_refh, pEnc->mbParam.edged_width,
292                   pEnc->mbParam.edged_height) < 0)                   pEnc->mbParam.edged_height) < 0)
# Line 287  Line 299 
299                  (&pEnc->f_refhv, pEnc->mbParam.edged_width,                  (&pEnc->f_refhv, pEnc->mbParam.edged_width,
300                   pEnc->mbParam.edged_height) < 0)                   pEnc->mbParam.edged_height) < 0)
301                  goto xvid_err_memory3;                  goto xvid_err_memory3;
302  #endif  
303          if (image_create          if (image_create
304                  (&pEnc->current->image, pEnc->mbParam.edged_width,                  (&pEnc->current->image, pEnc->mbParam.edged_width,
305                   pEnc->mbParam.edged_height) < 0)                   pEnc->mbParam.edged_height) < 0)
# Line 320  Line 332 
332    
333    
334          /* B Frames specific init */          /* B Frames specific init */
 #ifdef BFRAMES  
335    
336            pEnc->global = pParam->global;
337          pEnc->mbParam.max_bframes = pParam->max_bframes;          pEnc->mbParam.max_bframes = pParam->max_bframes;
338          pEnc->bquant_ratio = pParam->bquant_ratio;          pEnc->bquant_ratio = pParam->bquant_ratio;
339            pEnc->frame_drop_ratio = pParam->frame_drop_ratio;
340          pEnc->bframes = NULL;          pEnc->bframes = NULL;
341    
342          if (pEnc->mbParam.max_bframes > 0) {          if (pEnc->mbParam.max_bframes > 0) {
# Line 366  Line 379 
379          pEnc->bframenum_head = 0;          pEnc->bframenum_head = 0;
380          pEnc->bframenum_tail = 0;          pEnc->bframenum_tail = 0;
381          pEnc->flush_bframes = 0;          pEnc->flush_bframes = 0;
382            pEnc->bframenum_dx50bvop = -1;
383    
384          pEnc->mbParam.m_seconds = 0;          pEnc->queue = NULL;
385          pEnc->mbParam.m_ticks = 0;  
386  #endif  
387            if (pEnc->mbParam.max_bframes > 0) {
388                    int n;
389    
390                    pEnc->queue =
391                            xvid_malloc(pEnc->mbParam.max_bframes * sizeof(IMAGE),
392                                                    CACHE_LINE);
393    
394                    if (pEnc->queue == NULL)
395                            goto xvid_err_memory4;
396    
397                    for (n = 0; n < pEnc->mbParam.max_bframes; n++)
398                            image_null(&pEnc->queue[n]);
399    
400                    for (n = 0; n < pEnc->mbParam.max_bframes; n++) {
401                            if (image_create
402                                    (&pEnc->queue[n], pEnc->mbParam.edged_width,
403                                     pEnc->mbParam.edged_height) < 0)
404                                    goto xvid_err_memory5;
405    
406                    }
407            }
408    
409            pEnc->queue_head = 0;
410            pEnc->queue_tail = 0;
411            pEnc->queue_size = 0;
412    
413            pEnc->mbParam.m_stamp = 0;
414    
415            pEnc->m_framenum = 0;
416            pEnc->current->stamp = 0;
417            pEnc->reference->stamp = 0;
418    
419          pParam->handle = (void *) pEnc;          pParam->handle = (void *) pEnc;
420    
# Line 388  Line 433 
433          /*          /*
434           * We handle all XVID_ERR_MEMORY here, this makes the code lighter           * We handle all XVID_ERR_MEMORY here, this makes the code lighter
435           */           */
436  #ifdef BFRAMES  
437      xvid_err_memory5:
438    
439    
440            if (pEnc->mbParam.max_bframes > 0) {
441    
442                    for (i = 0; i < pEnc->mbParam.max_bframes; i++) {
443                            image_destroy(&pEnc->queue[i], pEnc->mbParam.edged_width,
444                                                      pEnc->mbParam.edged_height);
445                    }
446                    xvid_free(pEnc->queue);
447            }
448    
449    xvid_err_memory4:    xvid_err_memory4:
450    
451            if (pEnc->mbParam.max_bframes > 0) {
452    
453          for (i = 0; i < pEnc->mbParam.max_bframes; i++) {          for (i = 0; i < pEnc->mbParam.max_bframes; i++) {
454    
455                  if (pEnc->bframes[i] == NULL)                  if (pEnc->bframes[i] == NULL)
# Line 405  Line 465 
465          }          }
466    
467          xvid_free(pEnc->bframes);          xvid_free(pEnc->bframes);
468            }
 #endif  
469    
470    xvid_err_memory3:    xvid_err_memory3:
471  #ifdef _DEBUG  #ifdef _DEBUG_PSNR
472          image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width,          image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width,
473                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
474  #endif  #endif
475    
 #ifdef BFRAMES  
476          image_destroy(&pEnc->f_refh, pEnc->mbParam.edged_width,          image_destroy(&pEnc->f_refh, pEnc->mbParam.edged_width,
477                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
478          image_destroy(&pEnc->f_refv, pEnc->mbParam.edged_width,          image_destroy(&pEnc->f_refv, pEnc->mbParam.edged_width,
479                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
480          image_destroy(&pEnc->f_refhv, pEnc->mbParam.edged_width,          image_destroy(&pEnc->f_refhv, pEnc->mbParam.edged_width,
481                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
 #endif  
482    
483          image_destroy(&pEnc->current->image, pEnc->mbParam.edged_width,          image_destroy(&pEnc->current->image, pEnc->mbParam.edged_width,
484                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
# Line 466  Line 523 
523  int  int
524  encoder_destroy(Encoder * pEnc)  encoder_destroy(Encoder * pEnc)
525  {  {
526            int i;
527    
528          ENC_CHECK(pEnc);          ENC_CHECK(pEnc);
529    
530          /* B Frames specific */          /* B Frames specific */
531  #ifdef BFRAMES          if (pEnc->mbParam.max_bframes > 0) {
532          int i;  
533                    for (i = 0; i < pEnc->mbParam.max_bframes; i++) {
534    
535                            image_destroy(&pEnc->queue[i], pEnc->mbParam.edged_width,
536                                              pEnc->mbParam.edged_height);
537                    }
538                    xvid_free(pEnc->queue);
539            }
540    
541    
542            if (pEnc->mbParam.max_bframes > 0) {
543    
544          for (i = 0; i < pEnc->mbParam.max_bframes; i++) {          for (i = 0; i < pEnc->mbParam.max_bframes; i++) {
545    
# Line 483  Line 552 
552                  xvid_free(pEnc->bframes[i]->mbs);                  xvid_free(pEnc->bframes[i]->mbs);
553    
554                  xvid_free(pEnc->bframes[i]);                  xvid_free(pEnc->bframes[i]);
   
555          }          }
556    
557          xvid_free(pEnc->bframes);          xvid_free(pEnc->bframes);
558    
559  #endif          }
560    
561          /* All images, reference, current etc ... */          /* All images, reference, current etc ... */
562    
# Line 506  Line 574 
574                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
575          image_destroy(&pEnc->vInterHVf, pEnc->mbParam.edged_width,          image_destroy(&pEnc->vInterHVf, pEnc->mbParam.edged_width,
576                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
577  #ifdef BFRAMES  
578          image_destroy(&pEnc->f_refh, pEnc->mbParam.edged_width,          image_destroy(&pEnc->f_refh, pEnc->mbParam.edged_width,
579                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
580          image_destroy(&pEnc->f_refv, pEnc->mbParam.edged_width,          image_destroy(&pEnc->f_refv, pEnc->mbParam.edged_width,
581                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
582          image_destroy(&pEnc->f_refhv, pEnc->mbParam.edged_width,          image_destroy(&pEnc->f_refhv, pEnc->mbParam.edged_width,
583                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
584  #endif  
585  #ifdef _DEBUG  #ifdef _DEBUG_PSNR
586          image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width,          image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width,
587                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
588  #endif  #endif
# Line 532  Line 600 
600          return XVID_ERR_OK;          return XVID_ERR_OK;
601  }  }
602    
603    
604    static __inline void inc_frame_num(Encoder * pEnc)
605    {
606            pEnc->current->stamp = pEnc->mbParam.m_stamp;   // first frame is zero
607            pEnc->mbParam.m_stamp += pEnc->mbParam.fincr;
608    }
609    
610    
611    static __inline void
612    queue_image(Encoder * pEnc, XVID_ENC_FRAME * pFrame)
613    {
614            if (pEnc->queue_size >= pEnc->mbParam.max_bframes)
615            {
616                    DPRINTF(DPRINTF_DEBUG,"FATAL: QUEUE FULL");
617                    return;
618            }
619    
620            DPRINTF(DPRINTF_DEBUG,"*** QUEUE bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
621                                    pEnc->bframenum_head, pEnc->bframenum_tail,
622                                    pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
623    
624    
625            start_timer();
626            if (image_input
627                    (&pEnc->queue[pEnc->queue_tail], pEnc->mbParam.width, pEnc->mbParam.height,
628                     pEnc->mbParam.edged_width, pFrame->image, pFrame->colorspace))
629                    return;
630            stop_conv_timer();
631    
632            pEnc->queue_size++;
633            pEnc->queue_tail =  (pEnc->queue_tail + 1) % pEnc->mbParam.max_bframes;
634    }
635    
636    static __inline void
637    set_timecodes(FRAMEINFO* pCur,FRAMEINFO *pRef, int32_t time_base)
638    {
639    
640                    pCur->ticks = (int32_t)pCur->stamp % time_base;
641                    pCur->seconds =  ((int32_t)pCur->stamp / time_base)     - ((int32_t)pRef->stamp / time_base) ;
642    
643                    //HEAVY DEBUG OUTPUT    remove when timecodes prove to be stable
644    
645    /*              fprintf(stderr,"WriteVop:   %d - %d \n",
646                            ((int32_t)pCur->stamp / time_base), ((int32_t)pRef->stamp / time_base));
647                    fprintf(stderr,"set_timecodes: VOP %1d   stamp=%lld ref_stamp=%lld  base=%d\n",
648                            pCur->coding_type, pCur->stamp, pRef->stamp, time_base);
649                    fprintf(stderr,"set_timecodes: VOP %1d   seconds=%d   ticks=%d   (ref-sec=%d  ref-tick=%d)\n",
650                            pCur->coding_type, pCur->seconds, pCur->ticks, pRef->seconds, pRef->ticks);
651    
652    */
653    }
654    
655    
656    
657    
658    
659  /*****************************************************************************  /*****************************************************************************
660   * 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.  
661   *   *
662   * Returned values :   * Returned values :
663   *    - XVID_ERR_OK     - no errors   *    - XVID_ERR_OK     - no errors
# Line 544  Line 665 
665   *                        format   *                        format
666   ****************************************************************************/   ****************************************************************************/
667    
   
 #ifdef BFRAMES  
 /*****************************************************************************  
  * Frame encoder entry point for IPB capable encoder  
  ****************************************************************************/  
668  int  int
669  encoder_encode(Encoder * pEnc,  encoder_encode_bframes(Encoder * pEnc,
670                             XVID_ENC_FRAME * pFrame,                             XVID_ENC_FRAME * pFrame,
671                             XVID_ENC_STATS * pResult)                             XVID_ENC_STATS * pResult)
672  {  {
673          uint16_t x, y;          uint16_t x, y;
674          Bitstream bs;          Bitstream bs;
675          uint32_t bits;          uint32_t bits, mode;
676    
677  #ifdef _DEBUG          int input_valid = 1;
678    
679    #ifdef _DEBUG_PSNR
680          float psnr;          float psnr;
681          char temp[128];          char temp[128];
682  #endif  #endif
683    
684          ENC_CHECK(pEnc);          ENC_CHECK(pEnc);
685          ENC_CHECK(pFrame);          ENC_CHECK(pFrame);
686            ENC_CHECK(pFrame->image);
687    
688          start_global_timer();          start_global_timer();
689    
690          BitstreamInit(&bs, pFrame->bitstream, 0);          BitstreamInit(&bs, pFrame->bitstream, 0);
691    
692    ipvop_loop:
693    
694          /*          /*
695           * bframe "flush" code           * bframe "flush" code
696           */           */
# Line 584  Line 705 
705                           * frame as a pframe                           * frame as a pframe
706                           */                           */
707    
708                          /* ToDo : remove dprintf calls */                          DPRINTF(DPRINTF_DEBUG,"*** BFRAME (final frame) bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
709                          /*                                  pEnc->bframenum_head, pEnc->bframenum_tail,
710                             dprintf("--- PFRAME (final frame correction) --- ");                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
711                           */  
712                          pEnc->bframenum_tail--;                          pEnc->bframenum_tail--;
713                          SWAP(pEnc->current, pEnc->reference);                          SWAP(pEnc->current, pEnc->reference);
714    
# Line 597  Line 718 
718    
719                          BitstreamPad(&bs);                          BitstreamPad(&bs);
720                          pFrame->length = BitstreamLength(&bs);                          pFrame->length = BitstreamLength(&bs);
                         pFrame->input_consumed = 0;  
721                          pFrame->intra = 0;                          pFrame->intra = 0;
722    
723                          return XVID_ERR_OK;                          return XVID_ERR_OK;
724                  }                  }
725    
726                  /* ToDo : remove dprintf calls */  
727                  /*                  DPRINTF(DPRINTF_DEBUG,"*** BFRAME (flush) bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
728                     dprintf("--- BFRAME (flush) --- ");                                  pEnc->bframenum_head, pEnc->bframenum_tail,
729                   */                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
730    
731                  FrameCodeB(pEnc, pEnc->bframes[pEnc->bframenum_head], &bs, &bits);                  FrameCodeB(pEnc, pEnc->bframes[pEnc->bframenum_head], &bs, &bits);
732                  pEnc->bframenum_head++;                  pEnc->bframenum_head++;
733    
   
734                  BitstreamPad(&bs);                  BitstreamPad(&bs);
735                  pFrame->length = BitstreamLength(&bs);                  pFrame->length = BitstreamLength(&bs);
                 pFrame->input_consumed = 0;  
736                  pFrame->intra = 0;                  pFrame->intra = 0;
737    
738                    if (input_valid)
739                            queue_image(pEnc, pFrame);
740    
741                  return XVID_ERR_OK;                  return XVID_ERR_OK;
742          }          }
743    
744          if (pFrame->image == NULL) {          if (pEnc->bframenum_head > 0) {
745                  pFrame->length = 0;                  pEnc->bframenum_head = pEnc->bframenum_tail = 0;
746                  pFrame->input_consumed = 1;  
747                    /* write an empty marker to the bitstream.
748    
749                       for divx5 decoder compatibility, this marker must consist
750                       of a not-coded p-vop, with a time_base of zero, and time_increment
751                       indentical to the future-referece frame.
752                    */
753    
754                    if ((pEnc->global & XVID_GLOBAL_PACKED)) {
755                            int tmp;
756    
757                            DPRINTF(DPRINTF_DEBUG,"*** EMPTY bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
758                                    pEnc->bframenum_head, pEnc->bframenum_tail,
759                                    pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
760    
761                            BitstreamPad(&bs);
762    
763                            tmp = pEnc->current->seconds;
764                            pEnc->current->seconds = 0; /* force time_base = 0 */
765                            BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0);
766                            pEnc->current->seconds = tmp;
767    
768                            pFrame->length = BitstreamLength(&bs);
769                  pFrame->intra = 0;                  pFrame->intra = 0;
770    
771                            if (input_valid)
772                                    queue_image(pEnc, pFrame);
773    
774                  return XVID_ERR_OK;                  return XVID_ERR_OK;
775          }          }
776            }
777    
778          if (pEnc->bframenum_head > 0) {  
779                  pEnc->bframenum_head = pEnc->bframenum_tail = 0;  bvop_loop:
780    
781            if (pEnc->bframenum_dx50bvop != -1)
782            {
783    
784                    SWAP(pEnc->current, pEnc->reference);
785                    SWAP(pEnc->current, pEnc->bframes[pEnc->bframenum_dx50bvop]);
786    
787                    if ((pEnc->global & XVID_GLOBAL_DEBUG)) {
788                            image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 100, "DX50 IVOP");
789          }          }
790    
791          pEnc->flush_bframes = 0;                  if (input_valid)
792                    {
793                            queue_image(pEnc, pFrame);
794                            input_valid = 0;
795                    }
796    
797          /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%          } else if (input_valid) {
798           * Well there was a separation here so i put it in ANSI C  
799           * comment style :-)                  SWAP(pEnc->current, pEnc->reference);
800           * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */  
801                    start_timer();
802                    if (image_input
803                            (&pEnc->current->image, pEnc->mbParam.width, pEnc->mbParam.height,
804                            pEnc->mbParam.edged_width, pFrame->image, pFrame->colorspace))
805                            return XVID_ERR_FORMAT;
806                    stop_conv_timer();
807    
808                    // queue input frame, and dequue next image
809                    if (pEnc->queue_size > 0)
810                    {
811                            image_swap(&pEnc->current->image, &pEnc->queue[pEnc->queue_tail]);
812                            if (pEnc->queue_head != pEnc->queue_tail)
813                            {
814                                    image_swap(&pEnc->current->image, &pEnc->queue[pEnc->queue_head]);
815                            }
816                            pEnc->queue_head =  (pEnc->queue_head + 1) % pEnc->mbParam.max_bframes;
817                            pEnc->queue_tail =  (pEnc->queue_tail + 1) % pEnc->mbParam.max_bframes;
818                    }
819    
820            } else if (pEnc->queue_size > 0) {
821    
822          SWAP(pEnc->current, pEnc->reference);          SWAP(pEnc->current, pEnc->reference);
823    
824          EMMS();                  image_swap(&pEnc->current->image, &pEnc->queue[pEnc->queue_head]);
825                    pEnc->queue_head =  (pEnc->queue_head + 1) % pEnc->mbParam.max_bframes;
826                    pEnc->queue_size--;
827    
828            } else {
829    
830                    /* if nothing was encoded, write an 'ignore this frame' flag
831                       to the bitstream */
832    
833                    if (BitstreamPos(&bs) == 0) {
834    
835                            DPRINTF(DPRINTF_DEBUG,"*** SKIP bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
836                                    pEnc->bframenum_head, pEnc->bframenum_tail,
837                                    pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
838    
839                            BitstreamPutBits(&bs, 0x7f, 8);
840                            pFrame->intra = 0;
841                    }
842    
843                    pFrame->length = BitstreamLength(&bs);
844                    return XVID_ERR_OK;
845            }
846    
847            pEnc->flush_bframes = 0;
848    
849            emms();
850    
851            // only inc frame num, adapt quant, etc. if we havent seen it before
852            if (pEnc->bframenum_dx50bvop < 0 )
853            {
854          if (pFrame->quant == 0)          if (pFrame->quant == 0)
855                  pEnc->current->quant = RateControlGetQ(&pEnc->rate_control, 0);                  pEnc->current->quant = RateControlGetQ(&pEnc->rate_control, 0);
856          else          else
857                  pEnc->current->quant = pFrame->quant;                  pEnc->current->quant = pFrame->quant;
858    
859          if (pEnc->current->quant < 1)  /*              if (pEnc->current->quant < 1)
860                  pEnc->current->quant = 1;                  pEnc->current->quant = 1;
861    
862          if (pEnc->current->quant > 31)          if (pEnc->current->quant > 31)
863                  pEnc->current->quant = 31;                  pEnc->current->quant = 31;
864    */
865          pEnc->current->global_flags = pFrame->general;          pEnc->current->global_flags = pFrame->general;
866          pEnc->current->motion_flags = pFrame->motion;          pEnc->current->motion_flags = pFrame->motion;
867          pEnc->current->seconds = pEnc->mbParam.m_seconds;  
         pEnc->current->ticks = pEnc->mbParam.m_ticks;  
868          /* ToDo : dynamic fcode (in both directions) */          /* ToDo : dynamic fcode (in both directions) */
869          pEnc->current->fcode = pEnc->mbParam.m_fcode;          pEnc->current->fcode = pEnc->mbParam.m_fcode;
870          pEnc->current->bcode = pEnc->mbParam.m_fcode;          pEnc->current->bcode = pEnc->mbParam.m_fcode;
871    
872          start_timer();                  inc_frame_num(pEnc);
         if (image_input  
                 (&pEnc->current->image, pEnc->mbParam.width, pEnc->mbParam.height,  
                  pEnc->mbParam.edged_width, pFrame->image, pFrame->colorspace))  
                 return XVID_ERR_FORMAT;  
         stop_conv_timer();  
873    
874  #ifdef _DEBUG  #ifdef _DEBUG_PSNR
875          image_copy(&pEnc->sOriginal, &pEnc->current->image,          image_copy(&pEnc->sOriginal, &pEnc->current->image,
876                             pEnc->mbParam.edged_width, pEnc->mbParam.height);                             pEnc->mbParam.edged_width, pEnc->mbParam.height);
877  #endif  #endif
878    
879          EMMS();                  emms();
880    
881                    if ((pEnc->global & XVID_GLOBAL_DEBUG)) {
882                            image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 5,
883                                    "%i  if:%i  st:%i", pEnc->m_framenum++, pEnc->iFrameNum, pEnc->current->stamp);
884                    }
885    
886          /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%          /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
887           * Luminance masking           * Luminance masking
# Line 704  Line 912 
912                          }                          }
913    
914  #undef OFFSET  #undef OFFSET
   
915                  }                  }
916    
917                  xvid_free(temp_dquants);                  xvid_free(temp_dquants);
918          }          }
919    
920            }
921    
922          /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%          /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
923           * ivop/pvop/bvop selection           * ivop/pvop/bvop selection
924           * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */           * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
925    
926    
927          if (pEnc->iFrameNum == 0 || pFrame->intra == 1 ||          if (pEnc->iFrameNum == 0 || pFrame->intra == 1 || pEnc->bframenum_dx50bvop >= 0 ||
928                  (pFrame->intra < 0 && pEnc->iMaxKeyInterval > 0 &&                  (pFrame->intra < 0 && pEnc->iMaxKeyInterval > 0 &&
929                   pEnc->iFrameNum >= pEnc->iMaxKeyInterval)                   pEnc->iFrameNum >= pEnc->iMaxKeyInterval)
930                  || image_mad(&pEnc->reference->image, &pEnc->current->image,                  || /*image_mad(&pEnc->reference->image, &pEnc->current->image,
931                                           pEnc->mbParam.edged_width, pEnc->mbParam.width,                                           pEnc->mbParam.edged_width, pEnc->mbParam.width,
932                                           pEnc->mbParam.height) > 30) {                                           pEnc->mbParam.height) > 30) {*/
933                            2 == (mode = MEanalysis(&pEnc->reference->image, &pEnc->current->image,
934                                             &pEnc->mbParam, pEnc->current->mbs, pEnc->current->fcode))) {
935    
936                  /*                  /*
937                   * This will be coded as an Intra Frame                   * This will be coded as an Intra Frame
938                   */                   */
939    
940                  /* ToDo : Remove dprintf calls */                  DPRINTF(DPRINTF_DEBUG,"*** IFRAME bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
941                  /*                                  pEnc->bframenum_head, pEnc->bframenum_tail,
942                     dprintf("--- IFRAME ---");                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
                  */  
943    
944                  FrameCodeI(pEnc, &bs, &bits);                  if ((pEnc->global & XVID_GLOBAL_DEBUG)) {
945                            image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "IVOP");
946                    }
947    
948                    // when we reach an iframe in DX50BVOP mode, encode the last bframe as a pframe
949    
950                    if ((pEnc->global & XVID_GLOBAL_DX50BVOP) && pEnc->bframenum_tail > 0) {
951    
952                            pEnc->bframenum_tail--;
953                            pEnc->bframenum_dx50bvop = pEnc->bframenum_tail;
954    
955                            SWAP(pEnc->current, pEnc->bframes[pEnc->bframenum_dx50bvop]);
956                            if ((pEnc->global & XVID_GLOBAL_DEBUG)) {
957                                    image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 100, "DX50 BVOP->PVOP");
958                            }
959                            FrameCodeP(pEnc, &bs, &bits, 1, 0);
960    
961                            pFrame->intra = 0;
962    
963                    } else {
964    
965                            FrameCodeI(pEnc, &bs, &bits);
966                  pFrame->intra = 1;                  pFrame->intra = 1;
967    
968                            pEnc->bframenum_dx50bvop = -1;
969                    }
970    
971                  pEnc->flush_bframes = 1;                  pEnc->flush_bframes = 1;
972    
973                    if ((pEnc->global & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail > 0) {
974                            BitstreamPadAlways(&bs);
975                            input_valid = 0;
976                            goto ipvop_loop;
977                    }
978    
979                  /*                  /*
980                   * NB : sequences like "IIBB" decode fine with msfdam but,                   * NB : sequences like "IIBB" decode fine with msfdam but,
981                   *      go screwy with divx 5.00                   *      go screwy with divx 5.00
982                   */                   */
983          } else if (pEnc->bframenum_tail >= pEnc->mbParam.max_bframes) {          } else if (pEnc->bframenum_tail >= pEnc->mbParam.max_bframes || mode != 0) {
984                  /*                  /*
985                   * This will be coded as a Predicted Frame                   * This will be coded as a Predicted Frame
986                   */                   */
987    
988                  /* ToDo : Remove dprintf calls */                  DPRINTF(DPRINTF_DEBUG,"*** PFRAME bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
989                  /*                                  pEnc->bframenum_head, pEnc->bframenum_tail,
990                     dprintf("--- PFRAME ---");                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
991                   */  
992                    if ((pEnc->global & XVID_GLOBAL_DEBUG)) {
993                            image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "PVOP");
994                    }
995    
996                  FrameCodeP(pEnc, &bs, &bits, 1, 0);                  FrameCodeP(pEnc, &bs, &bits, 1, 0);
997                  pFrame->intra = 0;                  pFrame->intra = 0;
998                  pEnc->flush_bframes = 1;                  pEnc->flush_bframes = 1;
999    
1000                    if ((pEnc->global & XVID_GLOBAL_PACKED)) {
1001                            BitstreamPadAlways(&bs);
1002                            input_valid = 0;
1003                            goto ipvop_loop;
1004                    }
1005    
1006          } else {          } else {
1007                  /*                  /*
1008                   * This will be coded as a Bidirectional Frame                   * This will be coded as a Bidirectional Frame
1009                   */                   */
1010    
1011                  /* ToDo : Remove dprintf calls */                  if ((pEnc->global & XVID_GLOBAL_DEBUG)) {
1012                  /*                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "BVOP");
1013                     dprintf("--- BFRAME (store) ---  head=%i tail=%i",                  }
                    pEnc->bframenum_head,  
                    pEnc->bframenum_tail);  
                  */  
1014    
1015                  if (pFrame->bquant < 1) {                  if (pFrame->bquant < 1) {
1016                          pEnc->current->quant =                          pEnc->current->quant =
# Line 771  Line 1019 
1019                  } else {                  } else {
1020                          pEnc->current->quant = pFrame->bquant;                          pEnc->current->quant = pFrame->bquant;
1021                  }                  }
1022                    if (pEnc->current->quant < 1)
1023                            pEnc->current->quant = 1;
1024    
1025                    if (pEnc->current->quant > 31)
1026                            pEnc->current->quant = 31;
1027    
1028    
1029                            DPRINTF(DPRINTF_DEBUG,"*** BFRAME (store) bf: head=%i tail=%i   queue: head=%i tail=%i size=%i  quant=%i\n",
1030                                    pEnc->bframenum_head, pEnc->bframenum_tail,
1031                                    pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size,pEnc->current->quant);
1032    
1033    
1034    
1035                  /* store frame into bframe buffer & swap ref back to current */                  /* store frame into bframe buffer & swap ref back to current */
1036                  SWAP(pEnc->current, pEnc->bframes[pEnc->bframenum_tail]);                  SWAP(pEnc->current, pEnc->bframes[pEnc->bframenum_tail]);
# Line 780  Line 1040 
1040    
1041                  pFrame->intra = 0;                  pFrame->intra = 0;
1042                  pFrame->length = 0;                  pFrame->length = 0;
                 pFrame->input_consumed = 1;  
1043    
1044                  pEnc->mbParam.m_ticks += pEnc->mbParam.fincr;                  input_valid = 0;
1045                  if (pEnc->mbParam.m_ticks > pEnc->mbParam.fbase) {                  goto bvop_loop;
                         pEnc->mbParam.m_seconds++;  
                         pEnc->mbParam.m_ticks = 0;  
1046                  }                  }
1047    
1048                  return XVID_ERR_OK;          pEnc->iFrameNum++;
         }  
1049    
1050          BitstreamPad(&bs);          BitstreamPad(&bs);
1051          pFrame->length = BitstreamLength(&bs);          pFrame->length = BitstreamLength(&bs);
# Line 802  Line 1058 
1058                  pResult->ublks = pEnc->sStat.ublks;                  pResult->ublks = pEnc->sStat.ublks;
1059          }          }
1060    
1061          EMMS();          emms();
1062    
1063  #ifdef _DEBUG  #ifdef _DEBUG_PSNR
1064          psnr =          psnr =
1065                  image_psnr(&pEnc->sOriginal, &pEnc->current->image,                  image_psnr(&pEnc->sOriginal, &pEnc->current->image,
1066                                     pEnc->mbParam.edged_width, pEnc->mbParam.width,                                     pEnc->mbParam.edged_width, pEnc->mbParam.width,
# Line 819  Line 1075 
1075                                                    pFrame->length, pFrame->intra);                                                    pFrame->length, pFrame->intra);
1076          }          }
1077    
         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;  
   
1078          stop_global_timer();          stop_global_timer();
1079          write_timer();          write_timer();
1080    
1081          return XVID_ERR_OK;          return XVID_ERR_OK;
1082  }  }
1083  #else  
1084    
1085    
1086  /*****************************************************************************  /*****************************************************************************
1087   * Frame encoder entry point for IP capable encoder   * "original" IP frame encoder entry point
1088     *
1089     * Returned values :
1090     *    - XVID_ERR_OK     - no errors
1091     *    - XVID_ERR_FORMAT - the image subsystem reported the image had a wrong
1092     *                        format
1093   ****************************************************************************/   ****************************************************************************/
1094    
1095  int  int
1096  encoder_encode(Encoder * pEnc,  encoder_encode(Encoder * pEnc,
1097                             XVID_ENC_FRAME * pFrame,                             XVID_ENC_FRAME * pFrame,
# Line 846  Line 1102 
1102          uint32_t bits;          uint32_t bits;
1103          uint16_t write_vol_header = 0;          uint16_t write_vol_header = 0;
1104    
1105  #ifdef _DEBUG  #ifdef _DEBUG_PSNR
1106          float psnr;          float psnr;
1107          uint8_t temp[128];          uint8_t temp[128];
1108  #endif  #endif
# Line 864  Line 1120 
1120          pEnc->current->motion_flags = pFrame->motion;          pEnc->current->motion_flags = pFrame->motion;
1121          pEnc->mbParam.hint = &pFrame->hint;          pEnc->mbParam.hint = &pFrame->hint;
1122    
1123            inc_frame_num(pEnc);
1124    
1125            /* disable alternate scan flag if interlacing is not enabled */
1126            if ((pEnc->current->global_flags & XVID_ALTERNATESCAN) &&
1127                    !(pEnc->current->global_flags & XVID_INTERLACING))
1128            {
1129                    pEnc->current->global_flags -= XVID_ALTERNATESCAN;
1130            }
1131    
1132          start_timer();          start_timer();
1133          if (image_input          if (image_input
1134                  (&pEnc->current->image, pEnc->mbParam.width, pEnc->mbParam.height,                  (&pEnc->current->image, pEnc->mbParam.width, pEnc->mbParam.height,
# Line 871  Line 1136 
1136                  return XVID_ERR_FORMAT;                  return XVID_ERR_FORMAT;
1137          stop_conv_timer();          stop_conv_timer();
1138    
1139  #ifdef _DEBUG  #ifdef _DEBUG_PSNR
1140          image_copy(&pEnc->sOriginal, &pEnc->current->image,          image_copy(&pEnc->sOriginal, &pEnc->current->image,
1141                             pEnc->mbParam.edged_width, pEnc->mbParam.height);                             pEnc->mbParam.edged_width, pEnc->mbParam.height);
1142  #endif  #endif
1143    
1144          EMMS();          emms();
1145    
1146          BitstreamInit(&bs, pFrame->bitstream, 0);          BitstreamInit(&bs, pFrame->bitstream, 0);
1147    
# Line 886  Line 1151 
1151                  pEnc->current->quant = pFrame->quant;                  pEnc->current->quant = pFrame->quant;
1152          }          }
1153    
1154            if ((pEnc->current->global_flags & XVID_QUARTERPEL))
1155                    pEnc->mbParam.m_quarterpel = 1;
1156            else
1157                    pEnc->mbParam.m_quarterpel = 0;
1158    
1159          if ((pEnc->current->global_flags & XVID_LUMIMASKING)) {          if ((pEnc->current->global_flags & XVID_LUMIMASKING)) {
1160                  int *temp_dquants =                  int *temp_dquants =
1161                          (int *) xvid_malloc(pEnc->mbParam.mb_width *                          (int *) xvid_malloc(pEnc->mbParam.mb_width *
# Line 975  Line 1245 
1245                  pResult->ublks = pEnc->sStat.ublks;                  pResult->ublks = pEnc->sStat.ublks;
1246          }          }
1247    
1248          EMMS();          emms();
1249    
1250          if (pFrame->quant == 0) {          if (pFrame->quant == 0) {
1251                  RateControlUpdate(&pEnc->rate_control, pEnc->current->quant,                  RateControlUpdate(&pEnc->rate_control, pEnc->current->quant,
1252                                                    pFrame->length, pFrame->intra);                                                    pFrame->length, pFrame->intra);
1253          }          }
1254  #ifdef _DEBUG  #ifdef _DEBUG_PSNR
1255          psnr =          psnr =
1256                  image_psnr(&pEnc->sOriginal, &pEnc->current->image,                  image_psnr(&pEnc->sOriginal, &pEnc->current->image,
1257                                     pEnc->mbParam.edged_width, pEnc->mbParam.width,                                     pEnc->mbParam.edged_width, pEnc->mbParam.width,
# Line 998  Line 1268 
1268    
1269          return XVID_ERR_OK;          return XVID_ERR_OK;
1270  }  }
 #endif  
1271    
1272    
1273  static __inline void  static __inline void
# Line 1068  Line 1337 
1337                                  &pEnc->current->mbs[x + y * pEnc->mbParam.mb_width];                                  &pEnc->current->mbs[x + y * pEnc->mbParam.mb_width];
1338                          MVBLOCKHINT *bhint =                          MVBLOCKHINT *bhint =
1339                                  &hint->mvhint.block[x + y * pEnc->mbParam.mb_width];                                  &hint->mvhint.block[x + y * pEnc->mbParam.mb_width];
1340                          VECTOR pred[4];                          VECTOR pred;
1341                          VECTOR tmp;                          VECTOR tmp;
                         int32_t dummy[4];  
1342                          int vec;                          int vec;
1343    
1344                          pMB->mode =                          pMB->mode =
# Line 1090  Line 1358 
1358                                  tmp.x -= (tmp.x >= high) ? high * 2 : 0;                                  tmp.x -= (tmp.x >= high) ? high * 2 : 0;
1359                                  tmp.y -= (tmp.y >= high) ? high * 2 : 0;                                  tmp.y -= (tmp.y >= high) ? high * 2 : 0;
1360    
1361                                  get_pmvdata(pEnc->current->mbs, x, y, pEnc->mbParam.mb_width,                                  pred = get_pmv2(pEnc->current->mbs,pEnc->mbParam.mb_width,0,x,y,0);
                                                         0, pred, dummy);  
1362    
1363                                  for (vec = 0; vec < 4; ++vec) {                                  for (vec = 0; vec < 4; ++vec) {
1364                                          pMB->mvs[vec].x = tmp.x;                                          pMB->mvs[vec].x = tmp.x;
1365                                          pMB->mvs[vec].y = tmp.y;                                          pMB->mvs[vec].y = tmp.y;
1366                                          pMB->pmvs[vec].x = pMB->mvs[0].x - pred[0].x;                                          pMB->pmvs[vec].x = pMB->mvs[0].x - pred.x;
1367                                          pMB->pmvs[vec].y = pMB->mvs[0].y - pred[0].y;                                          pMB->pmvs[vec].y = pMB->mvs[0].y - pred.y;
1368                                  }                                  }
1369                          } else if (pMB->mode == MODE_INTER4V) {                          } else if (pMB->mode == MODE_INTER4V) {
1370                                  for (vec = 0; vec < 4; ++vec) {                                  for (vec = 0; vec < 4; ++vec) {
# Line 1110  Line 1377 
1377                                          tmp.x -= (tmp.x >= high) ? high * 2 : 0;                                          tmp.x -= (tmp.x >= high) ? high * 2 : 0;
1378                                          tmp.y -= (tmp.y >= high) ? high * 2 : 0;                                          tmp.y -= (tmp.y >= high) ? high * 2 : 0;
1379    
1380                                          get_pmvdata(pEnc->current->mbs, x, y,                                          pred = get_pmv2(pEnc->current->mbs,pEnc->mbParam.mb_width,0,x,y,vec);
                                                                 pEnc->mbParam.mb_width, vec, pred, dummy);  
1381    
1382                                          pMB->mvs[vec].x = tmp.x;                                          pMB->mvs[vec].x = tmp.x;
1383                                          pMB->mvs[vec].y = tmp.y;                                          pMB->mvs[vec].y = tmp.y;
1384                                          pMB->pmvs[vec].x = pMB->mvs[vec].x - pred[0].x;                                          pMB->pmvs[vec].x = pMB->mvs[vec].x - pred.x;
1385                                          pMB->pmvs[vec].y = pMB->mvs[vec].y - pred[0].y;                                          pMB->pmvs[vec].y = pMB->mvs[vec].y - pred.y;
1386                                  }                                  }
1387                          } else                          // intra / stuffing / not_coded                          } else                          // intra / stuffing / not_coded
1388                          {                          {
# Line 1246  Line 1512 
1512          pEnc->current->coding_type = I_VOP;          pEnc->current->coding_type = I_VOP;
1513    
1514          BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);          BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);
1515          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current);  
1516    #define DIVX501B481P "DivX501b481p"
1517            if ((pEnc->global & XVID_GLOBAL_PACKED)) {
1518                    BitstreamWriteUserData(bs, DIVX501B481P, strlen(DIVX501B481P));
1519            }
1520    
1521            set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase);
1522            BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);
1523    
1524          *pBits = BitstreamPos(bs);          *pBits = BitstreamPos(bs);
1525    
# Line 1269  Line 1542 
1542                          stop_prediction_timer();                          stop_prediction_timer();
1543    
1544                          start_timer();                          start_timer();
1545                            if (pEnc->current->global_flags & XVID_GREYSCALE)
1546                            {       pMB->cbp &= 0x3C;               /* keep only bits 5-2 */
1547                                    qcoeff[4*64+0]=0;               /* zero, because for INTRA MBs DC value is saved */
1548                                    qcoeff[5*64+0]=0;
1549                            }
1550                          MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->sStat);                          MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->sStat);
1551                          stop_coding_timer();                          stop_coding_timer();
1552                  }                  }
# Line 1290  Line 1568 
1568    
1569    
1570  #define INTRA_THRESHOLD 0.5  #define INTRA_THRESHOLD 0.5
1571    #define BFRAME_SKIP_THRESHHOLD 30
1572    
1573  static int  static int
1574  FrameCodeP(Encoder * pEnc,  FrameCodeP(Encoder * pEnc,
# Line 1304  Line 1583 
1583          DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE);
1584    
1585          int iLimit;          int iLimit;
1586          uint32_t x, y;          int x, y, k;
1587          int iSearchRange;          int iSearchRange;
1588          int bIntra;          int bIntra, skip_possible;
1589    
1590          /* IMAGE *pCurrent = &pEnc->current->image; */          /* IMAGE *pCurrent = &pEnc->current->image; */
1591          IMAGE *pRef = &pEnc->reference->image;          IMAGE *pRef = &pEnc->reference->image;
1592    
1593          start_timer();          start_timer();
1594          image_setedges(pRef, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,          image_setedges(pRef, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,
1595                                     pEnc->mbParam.width, pEnc->mbParam.height,                                     pEnc->mbParam.width, pEnc->mbParam.height);
                                    pEnc->current->global_flags & XVID_INTERLACING);  
1596          stop_edges_timer();          stop_edges_timer();
1597    
1598          pEnc->mbParam.m_rounding_type = 1 - pEnc->mbParam.m_rounding_type;          pEnc->mbParam.m_rounding_type = 1 - pEnc->mbParam.m_rounding_type;
# Line 1333  Line 1611 
1611                  image_interpolate(pRef, &pEnc->vInterH, &pEnc->vInterV,                  image_interpolate(pRef, &pEnc->vInterH, &pEnc->vInterV,
1612                                                    &pEnc->vInterHV, pEnc->mbParam.edged_width,                                                    &pEnc->vInterHV, pEnc->mbParam.edged_width,
1613                                                    pEnc->mbParam.edged_height,                                                    pEnc->mbParam.edged_height,
1614                                                      pEnc->mbParam.m_quarterpel,
1615                                                    pEnc->current->rounding_type);                                                    pEnc->current->rounding_type);
1616                  stop_inter_timer();                  stop_inter_timer();
1617          }          }
# Line 1340  Line 1619 
1619          start_timer();          start_timer();
1620          if (pEnc->current->global_flags & XVID_HINTEDME_SET) {          if (pEnc->current->global_flags & XVID_HINTEDME_SET) {
1621                  HintedMESet(pEnc, &bIntra);                  HintedMESet(pEnc, &bIntra);
1622            if (bIntra == 0) {
1623                            pEnc->current->fcode = FindFcode(&pEnc->mbParam, pEnc->current);
1624                            MotionEstimationHinted(&pEnc->mbParam, pEnc->current, pEnc->reference,
1625                                                                                            &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV);
1626                    }
1627    
1628          } else {          } else {
1629    
1630                  bIntra =                  bIntra =
1631                          MotionEstimation(&pEnc->mbParam, pEnc->current, pEnc->reference,                          MotionEstimation(&pEnc->mbParam, pEnc->current, pEnc->reference,
1632                                                           &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV,                                                           &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV,
1633                                                           iLimit);                                                           iLimit);
1634    
1635          }          }
1636          stop_motion_timer();          stop_motion_timer();
1637    
1638          if (bIntra == 1) {          if (bIntra == 1) return FrameCodeI(pEnc, bs, pBits);
                 return FrameCodeI(pEnc, bs, pBits);  
         }  
1639    
1640          pEnc->current->coding_type = P_VOP;          pEnc->current->coding_type = P_VOP;
1641    
1642          if (vol_header)          if (vol_header)
1643                  BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);                  BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);
1644    
1645          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current);  
1646            set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase);
1647            BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);
1648    
1649          *pBits = BitstreamPos(bs);          *pBits = BitstreamPos(bs);
1650    
1651          pEnc->sStat.iTextBits = 0;          pEnc->sStat.iTextBits = pEnc->sStat.iMvSum = pEnc->sStat.iMvCount =
         pEnc->sStat.iMvSum = 0;  
         pEnc->sStat.iMvCount = 0;  
1652          pEnc->sStat.kblks = pEnc->sStat.mblks = pEnc->sStat.ublks = 0;          pEnc->sStat.kblks = pEnc->sStat.mblks = pEnc->sStat.ublks = 0;
1653    
1654          for (y = 0; y < pEnc->mbParam.mb_height; y++) {          for (y = 0; y < pEnc->mbParam.mb_height; y++) {
# Line 1381  Line 1666 
1666                                                                           dct_codes, pEnc->mbParam.width,                                                                           dct_codes, pEnc->mbParam.width,
1667                                                                           pEnc->mbParam.height,                                                                           pEnc->mbParam.height,
1668                                                                           pEnc->mbParam.edged_width,                                                                           pEnc->mbParam.edged_width,
1669                                                                             pEnc->mbParam.m_quarterpel,
1670                                                                           pEnc->current->rounding_type);                                                                           pEnc->current->rounding_type);
1671                                  stop_comp_timer();                                  stop_comp_timer();
1672    
# Line 1398  Line 1684 
1684    
1685                                  pMB->field_pred = 0;                                  pMB->field_pred = 0;
1686    
1687                                    if (pMB->mode != MODE_NOT_CODED)
1688                                  pMB->cbp =                                  pMB->cbp =
1689                                          MBTransQuantInter(&pEnc->mbParam, pEnc->current, pMB, x, y,                                          MBTransQuantInter(&pEnc->mbParam, pEnc->current, pMB, x, y,
1690                                                                            dct_codes, qcoeff);                                                                            dct_codes, qcoeff);
# Line 1422  Line 1709 
1709                          }                          }
1710    
1711                          start_timer();                          start_timer();
1712    
1713                            /* Finished processing the MB, now check if to CODE or SKIP */
1714    
1715                            skip_possible = (pMB->cbp == 0) & (pMB->mode == MODE_INTER) &
1716                                                            (pMB->dquant == NO_CHANGE);
1717    
1718                            if(pEnc->mbParam.m_quarterpel)
1719                                    skip_possible &= (pMB->qmvs[0].x == 0) & (pMB->qmvs[0].y == 0);
1720                            else
1721                                    skip_possible &= (pMB->mvs[0].x == 0) & (pMB->mvs[0].y == 0);
1722    
1723                            if ((pMB->mode == MODE_NOT_CODED) || (skip_possible)) {
1724    /* This is a candidate for SKIPping, but check intermediate B-frames first */
1725    
1726                                    int bSkip = 1;
1727                                    pMB->mode = MODE_NOT_CODED;
1728    
1729                                    for (k=pEnc->bframenum_head; k< pEnc->bframenum_tail; k++)
1730                                    {
1731                                            int iSAD;
1732                                            iSAD = sad16(pEnc->reference->image.y + 16*y*pEnc->mbParam.edged_width + 16*x,
1733                                                                    pEnc->bframes[k]->image.y + 16*y*pEnc->mbParam.edged_width + 16*x,
1734                                                                    pEnc->mbParam.edged_width,BFRAME_SKIP_THRESHHOLD);
1735                                            if (iSAD >= BFRAME_SKIP_THRESHHOLD * pMB->quant)
1736                                            {       bSkip = 0;
1737                                                    break;
1738                                            }
1739                                    }
1740                                    if (!bSkip)
1741                                    {
1742                                            VECTOR predMV;
1743                                            if(pEnc->mbParam.m_quarterpel)
1744                                                    predMV = get_qpmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0);
1745                                            else
1746                                                    predMV = get_pmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0);
1747                                            pMB->pmvs[0].x = -predMV.x; pMB->pmvs[0].y = -predMV.y;
1748                                            pMB->mode = MODE_INTER;
1749                                            pMB->cbp = 0;
1750                          MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->sStat);                          MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->sStat);
1751                                    }
1752                                    else MBSkip(bs);
1753    
1754                            } else {
1755                                    if (pEnc->current->global_flags & XVID_GREYSCALE)
1756                                    {       pMB->cbp &= 0x3C;               /* keep only bits 5-2 */
1757                                            qcoeff[4*64+0]=0;               /* zero, because DC for INTRA MBs DC value is saved */
1758                                            qcoeff[5*64+0]=0;
1759                                    }
1760                                    MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->sStat);
1761                            }
1762    
1763                          stop_coding_timer();                          stop_coding_timer();
1764                  }                  }
1765          }          }
# Line 1441  Line 1778 
1778          iSearchRange = 1 << (3 + pEnc->mbParam.m_fcode);          iSearchRange = 1 << (3 + pEnc->mbParam.m_fcode);
1779    
1780          if ((fSigma > iSearchRange / 3)          if ((fSigma > iSearchRange / 3)
1781                  && (pEnc->mbParam.m_fcode <= 3))        // maximum search range 128                  && (pEnc->mbParam.m_fcode <= (3 + pEnc->mbParam.m_quarterpel))) // maximum search range 128
1782          {          {
1783                  pEnc->mbParam.m_fcode++;                  pEnc->mbParam.m_fcode++;
1784                  iSearchRange *= 2;                  iSearchRange *= 2;
1785          } else if ((fSigma < iSearchRange / 6)          } else if ((fSigma < iSearchRange / 6)
1786                             && (pEnc->sStat.fMvPrevSigma >= 0)                             && (pEnc->sStat.fMvPrevSigma >= 0)
1787                             && (pEnc->sStat.fMvPrevSigma < iSearchRange / 6)                             && (pEnc->sStat.fMvPrevSigma < iSearchRange / 6)
1788                             && (pEnc->mbParam.m_fcode >= 2))     // minimum search range 16                          && (pEnc->mbParam.m_fcode >= (2 + pEnc->mbParam.m_quarterpel))) // minimum search range 16
1789          {          {
1790                  pEnc->mbParam.m_fcode--;                  pEnc->mbParam.m_fcode--;
1791                  iSearchRange /= 2;                  iSearchRange /= 2;
# Line 1456  Line 1793 
1793    
1794          pEnc->sStat.fMvPrevSigma = fSigma;          pEnc->sStat.fMvPrevSigma = fSigma;
1795    
1796    #ifdef FRAMEDROP
1797            /* frame drop code */
1798            // DPRINTF(DPRINTF_DEBUG, "kmu %i %i %i", pEnc->sStat.kblks, pEnc->sStat.mblks, pEnc->sStat.ublks);
1799            if (pEnc->sStat.kblks + pEnc->sStat.mblks <
1800                    (pEnc->frame_drop_ratio * pEnc->mbParam.mb_width * pEnc->mbParam.mb_height) / 100)
1801            {
1802                    pEnc->sStat.kblks = pEnc->sStat.mblks = 0;
1803                    pEnc->sStat.ublks = pEnc->mbParam.mb_width * pEnc->mbParam.mb_height;
1804    
1805                    BitstreamReset(bs);
1806    
1807                    set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase);
1808                    BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 0);
1809    
1810                    // copy reference frame details into the current frame
1811                    pEnc->current->quant = pEnc->reference->quant;
1812                    pEnc->current->motion_flags = pEnc->reference->motion_flags;
1813                    pEnc->current->rounding_type = pEnc->reference->rounding_type;
1814                    pEnc->current->fcode = pEnc->reference->fcode;
1815                    pEnc->current->bcode = pEnc->reference->bcode;
1816                    image_copy(&pEnc->current->image, &pEnc->reference->image, pEnc->mbParam.edged_width, pEnc->mbParam.height);
1817                    memcpy(pEnc->current->mbs, pEnc->reference->mbs, sizeof(MACROBLOCK) * pEnc->mbParam.mb_width * pEnc->mbParam.mb_height);
1818    
1819            }
1820    #endif
1821    
1822          *pBits = BitstreamPos(bs) - *pBits;          *pBits = BitstreamPos(bs) - *pBits;
1823    
1824          return 0;                                       // inter          return 0;                                       // inter
1825  }  }
1826    
1827    
1828  #ifdef BFRAMES  static __inline void
 static void  
1829  FrameCodeB(Encoder * pEnc,  FrameCodeB(Encoder * pEnc,
1830                     FRAMEINFO * frame,                     FRAMEINFO * frame,
1831                     Bitstream * bs,                     Bitstream * bs,
# Line 1472  Line 1834 
1834          int16_t dct_codes[6 * 64];          int16_t dct_codes[6 * 64];
1835          int16_t qcoeff[6 * 64];          int16_t qcoeff[6 * 64];
1836          uint32_t x, y;          uint32_t x, y;
         VECTOR forward;  
         VECTOR backward;  
1837    
1838          IMAGE *f_ref = &pEnc->reference->image;          IMAGE *f_ref = &pEnc->reference->image;
1839          IMAGE *b_ref = &pEnc->current->image;          IMAGE *b_ref = &pEnc->current->image;
1840    
1841    #ifdef BFRAMES_DEC_DEBUG
1842            FILE *fp;
1843            static char first=0;
1844    #define BFRAME_DEBUG    if (!first && fp){ \
1845                    fprintf(fp,"Y=%3d   X=%3d   MB=%2d   CBP=%02X\n",y,x,mb->mode,mb->cbp); \
1846            }
1847    
1848            if (!first){
1849                    fp=fopen("C:\\XVIDDBGE.TXT","w");
1850            }
1851    #endif
1852    
1853          // forward          // forward
1854          image_setedges(f_ref, pEnc->mbParam.edged_width,          image_setedges(f_ref, pEnc->mbParam.edged_width,
1855                                     pEnc->mbParam.edged_height, pEnc->mbParam.width,                                     pEnc->mbParam.edged_height, pEnc->mbParam.width,
1856                                     pEnc->mbParam.height,                                     pEnc->mbParam.height);
                                    frame->global_flags & XVID_INTERLACING);  
1857          start_timer();          start_timer();
1858          image_interpolate(f_ref, &pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv,          image_interpolate(f_ref, &pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv,
1859                                            pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,                                            pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,
1860                                            0);                                            pEnc->mbParam.m_quarterpel, 0);
1861          stop_inter_timer();          stop_inter_timer();
1862    
1863          // backward          // backward
1864          image_setedges(b_ref, pEnc->mbParam.edged_width,          image_setedges(b_ref, pEnc->mbParam.edged_width,
1865                                     pEnc->mbParam.edged_height, pEnc->mbParam.width,                                     pEnc->mbParam.edged_height, pEnc->mbParam.width,
1866                                     pEnc->mbParam.height,                                     pEnc->mbParam.height);
                                    frame->global_flags & XVID_INTERLACING);  
1867          start_timer();          start_timer();
1868          image_interpolate(b_ref, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV,          image_interpolate(b_ref, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV,
1869                                            pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,                                            pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,
1870                                            0);                                            pEnc->mbParam.m_quarterpel, 0);
1871          stop_inter_timer();          stop_inter_timer();
1872    
1873          start_timer();          start_timer();
1874          MotionEstimationBVOP(&pEnc->mbParam, frame, pEnc->reference->mbs, f_ref,  
1875            MotionEstimationBVOP(&pEnc->mbParam, frame,
1876                    ((int32_t)(pEnc->current->stamp - frame->stamp)),                               // time_bp
1877                    ((int32_t)(pEnc->current->stamp - pEnc->reference->stamp)),     // time_pp
1878                            pEnc->reference->mbs, f_ref,
1879                                                   &pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv,                                                   &pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv,
1880                                                   pEnc->current->mbs, b_ref, &pEnc->vInterH,                                                   pEnc->current->mbs, b_ref, &pEnc->vInterH,
1881                                                   &pEnc->vInterV, &pEnc->vInterHV);                                                   &pEnc->vInterV, &pEnc->vInterHV);
# Line 1515  Line 1889 
1889             } */             } */
1890    
1891          frame->coding_type = B_VOP;          frame->coding_type = B_VOP;
1892          BitstreamWriteVopHeader(bs, &pEnc->mbParam, frame);  
1893            set_timecodes(frame, pEnc->reference,pEnc->mbParam.fbase);
1894            BitstreamWriteVopHeader(bs, &pEnc->mbParam, frame, 1);
1895    
1896          *pBits = BitstreamPos(bs);          *pBits = BitstreamPos(bs);
1897    
# Line 1526  Line 1902 
1902    
1903    
1904          for (y = 0; y < pEnc->mbParam.mb_height; y++) {          for (y = 0; y < pEnc->mbParam.mb_height; y++) {
                 // reset prediction  
   
                 forward.x = 0;  
                 forward.y = 0;  
                 backward.x = 0;  
                 backward.y = 0;  
   
1905                  for (x = 0; x < pEnc->mbParam.mb_width; x++) {                  for (x = 0; x < pEnc->mbParam.mb_width; x++) {
1906                          MACROBLOCK *f_mb =                          MACROBLOCK * const mb = &frame->mbs[x + y * pEnc->mbParam.mb_width];
1907                                  &pEnc->reference->mbs[x + y * pEnc->mbParam.mb_width];                          int direction = pEnc->global & XVID_ALTERNATESCAN ? 2 : 0;
                         MACROBLOCK *b_mb =  
                                 &pEnc->current->mbs[x + y * pEnc->mbParam.mb_width];  
                         MACROBLOCK *mb = &frame->mbs[x + y * pEnc->mbParam.mb_width];  
1908    
1909                          // decoder ignores mb when refence block is INTER(0,0), CBP=0                          // decoder ignores mb when refence block is INTER(0,0), CBP=0
1910                          if (mb->mode == MODE_NOT_CODED) {                          if (mb->mode == MODE_NOT_CODED) {
1911                                  mb->mvs[0].x = 0;                                  //mb->mvs[0].x = mb->mvs[0].y = mb->cbp = 0;
                                 mb->mvs[0].y = 0;  
1912                                  continue;                                  continue;
1913                          }                          }
1914    
1915                            if (mb->mode != MODE_DIRECT_NONE_MV) {
1916                          MBMotionCompensationBVOP(&pEnc->mbParam, mb, x, y, &frame->image,                          MBMotionCompensationBVOP(&pEnc->mbParam, mb, x, y, &frame->image,
1917                                                                           f_ref, &pEnc->f_refh, &pEnc->f_refv,                                                                           f_ref, &pEnc->f_refh, &pEnc->f_refv,
1918                                                                           &pEnc->f_refhv, b_ref, &pEnc->vInterH,                                                                           &pEnc->f_refhv, b_ref, &pEnc->vInterH,
1919                                                                           &pEnc->vInterV, &pEnc->vInterHV,                                                                           &pEnc->vInterV, &pEnc->vInterHV,
1920                                                                           dct_codes);                                                                           dct_codes);
1921    
1922                                    if (mb->mode == MODE_DIRECT_NO4V) mb->mode = MODE_DIRECT;
1923                          mb->quant = frame->quant;                          mb->quant = frame->quant;
                         mb->cbp =  
                                 MBTransQuantInter(&pEnc->mbParam, frame, mb, x, y, dct_codes,  
                                                                   qcoeff);  
                         //mb->cbp = MBTransQuantBVOP(&pEnc->mbParam, x, y, dct_codes, qcoeff, &frame->image, frame->quant);  
1924    
1925                                    mb->cbp =
1926                                            MBTransQuantInterBVOP(&pEnc->mbParam, frame, mb, dct_codes, qcoeff);
1927    
1928                          if ((mb->mode == MODE_INTERPOLATE || mb->mode == MODE_DIRECT)                                  if ( (mb->mode == MODE_DIRECT) && (mb->cbp == 0)
1929                                  && mb->cbp == 0 && mb->mvs[0].x == 0 && mb->mvs[0].y == 0) {                                          && (mb->pmvs[3].x == 0) && (mb->pmvs[3].y == 0) ) {
1930                                  mb->mode = 5;   // skipped                                          mb->mode = MODE_DIRECT_NONE_MV; // skipped
1931                          }                          }
   
                         if (mb->mode == MODE_INTERPOLATE || mb->mode == MODE_FORWARD) {  
                                 mb->pmvs[0].x = mb->mvs[0].x - forward.x;  
                                 mb->pmvs[0].y = mb->mvs[0].y - forward.y;  
                                 forward.x = mb->mvs[0].x;  
                                 forward.y = mb->mvs[0].y;  
1932                          }                          }
1933    
1934                          if (mb->mode == MODE_INTERPOLATE || mb->mode == MODE_BACKWARD) {  #ifdef BFRAMES_DEC_DEBUG
1935                                  mb->b_pmvs[0].x = mb->b_mvs[0].x - backward.x;          BFRAME_DEBUG
1936                                  mb->b_pmvs[0].y = mb->b_mvs[0].y - backward.y;  #endif
                                 backward.x = mb->b_mvs[0].x;  
                                 backward.y = mb->b_mvs[0].y;  
                         }  
 //          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);  
   
1937                          start_timer();                          start_timer();
1938                          MBCodingBVOP(mb, qcoeff, frame->fcode, frame->bcode, bs,                          MBCodingBVOP(mb, qcoeff, frame->fcode, frame->bcode, bs,
1939                                                   &pEnc->sStat);                                                   &pEnc->sStat, direction);
1940                          stop_coding_timer();                          stop_coding_timer();
1941                  }                  }
1942          }          }
# Line 1592  Line 1946 
1946          // TODO: dynamic fcode/bcode ???          // TODO: dynamic fcode/bcode ???
1947    
1948          *pBits = BitstreamPos(bs) - *pBits;          *pBits = BitstreamPos(bs) - *pBits;
1949    
1950    #ifdef BFRAMES_DEC_DEBUG
1951            if (!first){
1952                    first=1;
1953                    if (fp)
1954                            fclose(fp);
1955  }  }
1956  #endif  #endif
1957    }
1958    
1959    
1960    /*      in case internal output is needed somewhere... */
1961    /*      {
1962            FILE *filehandle;
1963            filehandle=fopen("last-b.pgm","wb");
1964            if (filehandle)
1965            {
1966                    fprintf(filehandle,"P5\n\n");           //
1967                    fprintf(filehandle,"%d %d 255\n",pEnc->mbParam.edged_width,pEnc->mbParam.edged_height);
1968                    fwrite(frame->image.y,pEnc->mbParam.edged_width,pEnc->mbParam.edged_height,filehandle);
1969                    fclose(filehandle);
1970                    }
1971            }
1972    */

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

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