[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 1682, Fri Feb 24 08:46:22 2006 UTC revision 1766, Thu Dec 14 13:09:00 2006 UTC
# Line 21  Line 21 
21   *  along with this program ; if not, write to the Free Software   *  along with this program ; if not, write to the Free Software
22   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
23   *   *
24   * $Id: encoder.c,v 1.126 2006-02-24 08:46:22 syskin Exp $   * $Id: encoder.c,v 1.129 2006-12-14 13:09:00 Isibaar Exp $
25   *   *
26   ****************************************************************************/   ****************************************************************************/
27    
# Line 662  Line 662 
662                  xvid_free(pEnc->temp_dquants);                  xvid_free(pEnc->temp_dquants);
663          }          }
664    
665            if ((pEnc->mbParam.plugin_flags & XVID_REQLAMBDA)) {
666                    xvid_free(pEnc->temp_lambda);
667            }
668    
669          if (pEnc->num_plugins>0) {          if (pEnc->num_plugins>0) {
670                  xvid_plg_destroy_t pdestroy;                  xvid_plg_destroy_t pdestroy;
# Line 767  Line 770 
770    
771                  if(pEnc->mbParam.plugin_flags & XVID_REQLAMBDA) {                  if(pEnc->mbParam.plugin_flags & XVID_REQLAMBDA) {
772                          int block = 0;                          int block = 0;
773                            emms();
774                          data.lambda = pEnc->temp_lambda;                          data.lambda = pEnc->temp_lambda;
775                          for(i = 0;i < pEnc->mbParam.mb_height; i++)                          for(i = 0;i < pEnc->mbParam.mb_height; i++)
776                                  for(j = 0;j < pEnc->mbParam.mb_width; j++)                                  for(j = 0;j < pEnc->mbParam.mb_width; j++)
# Line 1709  Line 1713 
1713    
1714          if (pEnc->num_threads > 0) {          if (pEnc->num_threads > 0) {
1715                  /* multithreaded motion estimation - dispatch threads */                  /* multithreaded motion estimation - dispatch threads */
1716    
1717                    void * status;
1718                  int rows_per_thread = (pParam->mb_height + pEnc->num_threads - 1)/pEnc->num_threads;                  int rows_per_thread = (pParam->mb_height + pEnc->num_threads - 1)/pEnc->num_threads;
1719    
1720                  for (k = 0; k < pEnc->num_threads; k++) {                  for (k = 0; k < pEnc->num_threads; k++) {
# Line 1726  Line 1732 
1732                          pEnc->motionData[k].RefQ = pEnc->vInterH.u + 16*k*pParam->edged_width;                          pEnc->motionData[k].RefQ = pEnc->vInterH.u + 16*k*pParam->edged_width;
1733                  }                  }
1734    
1735                  for (k = 0; k < pEnc->num_threads; k++) {                  for (k = 1; k < pEnc->num_threads; k++) {
1736                          pthread_create(&pEnc->motionData[k].handle, NULL,                          pthread_create(&pEnc->motionData[k].handle, NULL,
1737                                  (void*)MotionEstimateSMP, (void*)&pEnc->motionData[k]);                                  (void*)MotionEstimateSMP, (void*)&pEnc->motionData[k]);
1738                  }                  }
1739    
1740                    MotionEstimateSMP(&pEnc->motionData[0]);
1741    
1742                    for (k = 1; k < pEnc->num_threads; k++) {
1743                            pthread_join(pEnc->motionData[k].handle, &status);
1744                    }
1745    
1746                    current->fcode = 0;
1747                    for (k = 0; k < pEnc->num_threads; k++) {
1748                            current->sStat.iMvSum += pEnc->motionData[k].mvSum;
1749                            current->sStat.iMvCount += pEnc->motionData[k].mvCount;
1750                            if (pEnc->motionData[k].minfcode > current->fcode)
1751                                    current->fcode = pEnc->motionData[k].minfcode;
1752                    }
1753    
1754          } else {          } else {
1755                  /* regular ME */                  /* regular ME */
1756    
# Line 1745  Line 1766 
1766          BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 1, current->mbs[0].quant);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 1, current->mbs[0].quant);
1767    
1768          for (y = 0; y < mb_height; y++) {          for (y = 0; y < mb_height; y++) {
   
                 if (pEnc->num_threads > 0) {  
                         /* in multithreaded encoding, only proceed with a row of macroblocks  
                                 if ME finished with that row */  
                         while (pEnc->motionData[y%pEnc->num_threads].complete_count_self[y/pEnc->num_threads] != mb_width)  
                                 sched_yield();  
                 }  
   
1769                  for (x = 0; x < mb_width; x++) {                  for (x = 0; x < mb_width; x++) {
1770                          MACROBLOCK *pMB = &current->mbs[x + y * pParam->mb_width];                          MACROBLOCK *pMB = &current->mbs[x + y * pParam->mb_width];
1771                          int skip_possible;                          int skip_possible;
# Line 1863  Line 1876 
1876                  }                  }
1877          }          }
1878    
         if (pEnc->num_threads > 0) {  
                 void * status;  
                 for (k = 0; k < pEnc->num_threads; k++) {  
                         pthread_join(pEnc->motionData[k].handle, &status);  
                 }  
   
                 for (k = 0; k < pEnc->num_threads; k++) {  
                         current->sStat.iMvSum += pEnc->motionData[k].mvSum;  
                         current->sStat.iMvCount += pEnc->motionData[k].mvCount;  
                 }  
         }  
   
1879          emms();          emms();
1880          updateFcode(&current->sStat, pEnc);          updateFcode(&current->sStat, pEnc);
1881    
# Line 2005  Line 2006 
2006    
2007          frame->fcode = frame->bcode = pEnc->current->fcode;          frame->fcode = frame->bcode = pEnc->current->fcode;
2008    
2009            start_timer();
2010          if (pEnc->num_threads > 0) {          if (pEnc->num_threads > 0) {
2011                    void * status;
2012                  int k;                  int k;
2013                  /* multithreaded motion estimation - dispatch threads */                  /* multithreaded motion estimation - dispatch threads */
2014                  int rows_per_thread = (pEnc->mbParam.mb_height + pEnc->num_threads - 1)/pEnc->num_threads;                  int rows_per_thread = (pEnc->mbParam.mb_height + pEnc->num_threads - 1)/pEnc->num_threads;
# Line 2031  Line 2034 
2034                          pEnc->motionData[k].RefQ = pEnc->vInterH.u + 16*k*pEnc->mbParam.edged_width;                          pEnc->motionData[k].RefQ = pEnc->vInterH.u + 16*k*pEnc->mbParam.edged_width;
2035                  }                  }
2036    
2037                  for (k = 0; k < pEnc->num_threads; k++) {                  for (k = 1; k < pEnc->num_threads; k++) {
2038                          pthread_create(&pEnc->motionData[k].handle, NULL,                          pthread_create(&pEnc->motionData[k].handle, NULL,
2039                                  (void*)SMPMotionEstimationBVOP, (void*)&pEnc->motionData[k]);                                  (void*)SMPMotionEstimationBVOP, (void*)&pEnc->motionData[k]);
2040                  }                  }
2041    
2042                    SMPMotionEstimationBVOP(&pEnc->motionData[0]);
2043    
2044                    for (k = 1; k < pEnc->num_threads; k++) {
2045                            pthread_join(pEnc->motionData[k].handle, &status);
2046                    }
2047    
2048                    frame->fcode = frame->bcode = 0;
2049                    for (k = 0; k < pEnc->num_threads; k++) {
2050                            if (pEnc->motionData[k].minfcode > frame->fcode)
2051                                    frame->fcode = pEnc->motionData[k].minfcode;
2052                            if (pEnc->motionData[k].minbcode > frame->bcode)
2053                                    frame->bcode = pEnc->motionData[k].minbcode;
2054                    }
2055          } else {          } else {
                 start_timer();  
2056                  MotionEstimationBVOP(&pEnc->mbParam, frame,                  MotionEstimationBVOP(&pEnc->mbParam, frame,
2057                                                           ((int32_t)(pEnc->current->stamp - frame->stamp)),                              /* time_bp */                                                           ((int32_t)(pEnc->current->stamp - frame->stamp)),                              /* time_bp */
2058                                                           ((int32_t)(pEnc->current->stamp - pEnc->reference->stamp)),    /* time_pp */                                                           ((int32_t)(pEnc->current->stamp - pEnc->reference->stamp)),    /* time_pp */
# Line 2044  Line 2060 
2060                                                           &pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv,                                                           &pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv,
2061                                                           pEnc->current, b_ref, &pEnc->vInterH,                                                           pEnc->current, b_ref, &pEnc->vInterH,
2062                                                           &pEnc->vInterV, &pEnc->vInterHV);                                                           &pEnc->vInterV, &pEnc->vInterHV);
                 stop_motion_timer();  
2063          }          }
2064            stop_motion_timer();
2065    
2066          set_timecodes(frame, pEnc->reference,pEnc->mbParam.fbase);          set_timecodes(frame, pEnc->reference,pEnc->mbParam.fbase);
2067          BitstreamWriteVopHeader(bs, &pEnc->mbParam, frame, 1, frame->quant);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, frame, 1, frame->quant);
# Line 2059  Line 2075 
2075          frame->sStat.kblks = frame->sStat.ublks = 0;          frame->sStat.kblks = frame->sStat.ublks = 0;
2076    
2077          for (y = 0; y < pEnc->mbParam.mb_height; y++) {          for (y = 0; y < pEnc->mbParam.mb_height; y++) {
   
                 if (pEnc->num_threads > 0) {  
                         /* in multithreaded encoding, only proceed with a row of macroblocks  
                                 if ME finished with that row */  
                         while (pEnc->motionData[y%pEnc->num_threads].complete_count_self[y/pEnc->num_threads] != pEnc->mbParam.mb_width)  
                                 sched_yield();  
                 }  
   
2078                  for (x = 0; x < pEnc->mbParam.mb_width; x++) {                  for (x = 0; x < pEnc->mbParam.mb_width; x++) {
2079                          MACROBLOCK * const mb = &frame->mbs[x + y * pEnc->mbParam.mb_width];                          MACROBLOCK * const mb = &frame->mbs[x + y * pEnc->mbParam.mb_width];
2080    
# Line 2110  Line 2118 
2118                          stop_coding_timer();                          stop_coding_timer();
2119                  }                  }
2120          }          }
   
         if (pEnc->num_threads > 0) {  
                 void * status;  
                 int k;  
                 for (k = 0; k < pEnc->num_threads; k++) {  
                         pthread_join(pEnc->motionData[k].handle, &status);  
                 }  
         }  
   
2121          emms();          emms();
2122    
2123          BitstreamPadAlways(bs); /* next_start_code() at the end of VideoObjectPlane() */          BitstreamPadAlways(bs); /* next_start_code() at the end of VideoObjectPlane() */

Legend:
Removed from v.1682  
changed lines
  Added in v.1766

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