[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 1770, Thu Feb 8 13:10:24 2007 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.130 2007-02-08 13:10:24 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 1303  Line 1307 
1307                  if (pEnc->current->stamp > 0) {                  if (pEnc->current->stamp > 0) {
1308                          call_plugins(pEnc, pEnc->reference, &pEnc->sOriginal, XVID_PLG_AFTER, NULL, NULL, stats);                          call_plugins(pEnc, pEnc->reference, &pEnc->sOriginal, XVID_PLG_AFTER, NULL, NULL, stats);
1309                  }                  }
1310                  else          else if (stats) {
1311                          stats->type = XVID_TYPE_NOTHING;                          stats->type = XVID_TYPE_NOTHING;
1312          }          }
1313            }
1314    
1315          /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%          /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1316           * closed-gop           * closed-gop
# Line 1709  Line 1714 
1714    
1715          if (pEnc->num_threads > 0) {          if (pEnc->num_threads > 0) {
1716                  /* multithreaded motion estimation - dispatch threads */                  /* multithreaded motion estimation - dispatch threads */
1717    
1718                    void * status;
1719                  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;
1720    
1721                  for (k = 0; k < pEnc->num_threads; k++) {                  for (k = 0; k < pEnc->num_threads; k++) {
# Line 1726  Line 1733 
1733                          pEnc->motionData[k].RefQ = pEnc->vInterH.u + 16*k*pParam->edged_width;                          pEnc->motionData[k].RefQ = pEnc->vInterH.u + 16*k*pParam->edged_width;
1734                  }                  }
1735    
1736                  for (k = 0; k < pEnc->num_threads; k++) {                  for (k = 1; k < pEnc->num_threads; k++) {
1737                          pthread_create(&pEnc->motionData[k].handle, NULL,                          pthread_create(&pEnc->motionData[k].handle, NULL,
1738                                  (void*)MotionEstimateSMP, (void*)&pEnc->motionData[k]);                                  (void*)MotionEstimateSMP, (void*)&pEnc->motionData[k]);
1739                  }                  }
1740    
1741                    MotionEstimateSMP(&pEnc->motionData[0]);
1742    
1743                    for (k = 1; k < pEnc->num_threads; k++) {
1744                            pthread_join(pEnc->motionData[k].handle, &status);
1745                    }
1746    
1747                    current->fcode = 0;
1748                    for (k = 0; k < pEnc->num_threads; k++) {
1749                            current->sStat.iMvSum += pEnc->motionData[k].mvSum;
1750                            current->sStat.iMvCount += pEnc->motionData[k].mvCount;
1751                            if (pEnc->motionData[k].minfcode > current->fcode)
1752                                    current->fcode = pEnc->motionData[k].minfcode;
1753                    }
1754    
1755          } else {          } else {
1756                  /* regular ME */                  /* regular ME */
1757    
# Line 1745  Line 1767 
1767          BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 1, current->mbs[0].quant);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 1, current->mbs[0].quant);
1768    
1769          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();  
                 }  
   
1770                  for (x = 0; x < mb_width; x++) {                  for (x = 0; x < mb_width; x++) {
1771                          MACROBLOCK *pMB = &current->mbs[x + y * pParam->mb_width];                          MACROBLOCK *pMB = &current->mbs[x + y * pParam->mb_width];
1772                          int skip_possible;                          int skip_possible;
# Line 1863  Line 1877 
1877                  }                  }
1878          }          }
1879    
         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;  
                 }  
         }  
   
1880          emms();          emms();
1881          updateFcode(&current->sStat, pEnc);          updateFcode(&current->sStat, pEnc);
1882    
# Line 2005  Line 2007 
2007    
2008          frame->fcode = frame->bcode = pEnc->current->fcode;          frame->fcode = frame->bcode = pEnc->current->fcode;
2009    
2010            start_timer();
2011          if (pEnc->num_threads > 0) {          if (pEnc->num_threads > 0) {
2012                    void * status;
2013                  int k;                  int k;
2014                  /* multithreaded motion estimation - dispatch threads */                  /* multithreaded motion estimation - dispatch threads */
2015                  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 2035 
2035                          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;
2036                  }                  }
2037    
2038                  for (k = 0; k < pEnc->num_threads; k++) {                  for (k = 1; k < pEnc->num_threads; k++) {
2039                          pthread_create(&pEnc->motionData[k].handle, NULL,                          pthread_create(&pEnc->motionData[k].handle, NULL,
2040                                  (void*)SMPMotionEstimationBVOP, (void*)&pEnc->motionData[k]);                                  (void*)SMPMotionEstimationBVOP, (void*)&pEnc->motionData[k]);
2041                  }                  }
2042    
2043                    SMPMotionEstimationBVOP(&pEnc->motionData[0]);
2044    
2045                    for (k = 1; k < pEnc->num_threads; k++) {
2046                            pthread_join(pEnc->motionData[k].handle, &status);
2047                    }
2048    
2049                    frame->fcode = frame->bcode = 0;
2050                    for (k = 0; k < pEnc->num_threads; k++) {
2051                            if (pEnc->motionData[k].minfcode > frame->fcode)
2052                                    frame->fcode = pEnc->motionData[k].minfcode;
2053                            if (pEnc->motionData[k].minbcode > frame->bcode)
2054                                    frame->bcode = pEnc->motionData[k].minbcode;
2055                    }
2056          } else {          } else {
                 start_timer();  
2057                  MotionEstimationBVOP(&pEnc->mbParam, frame,                  MotionEstimationBVOP(&pEnc->mbParam, frame,
2058                                                           ((int32_t)(pEnc->current->stamp - frame->stamp)),                              /* time_bp */                                                           ((int32_t)(pEnc->current->stamp - frame->stamp)),                              /* time_bp */
2059                                                           ((int32_t)(pEnc->current->stamp - pEnc->reference->stamp)),    /* time_pp */                                                           ((int32_t)(pEnc->current->stamp - pEnc->reference->stamp)),    /* time_pp */
# Line 2044  Line 2061 
2061                                                           &pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv,                                                           &pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv,
2062                                                           pEnc->current, b_ref, &pEnc->vInterH,                                                           pEnc->current, b_ref, &pEnc->vInterH,
2063                                                           &pEnc->vInterV, &pEnc->vInterHV);                                                           &pEnc->vInterV, &pEnc->vInterHV);
                 stop_motion_timer();  
2064          }          }
2065            stop_motion_timer();
2066    
2067          set_timecodes(frame, pEnc->reference,pEnc->mbParam.fbase);          set_timecodes(frame, pEnc->reference,pEnc->mbParam.fbase);
2068          BitstreamWriteVopHeader(bs, &pEnc->mbParam, frame, 1, frame->quant);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, frame, 1, frame->quant);
# Line 2059  Line 2076 
2076          frame->sStat.kblks = frame->sStat.ublks = 0;          frame->sStat.kblks = frame->sStat.ublks = 0;
2077    
2078          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();  
                 }  
   
2079                  for (x = 0; x < pEnc->mbParam.mb_width; x++) {                  for (x = 0; x < pEnc->mbParam.mb_width; x++) {
2080                          MACROBLOCK * const mb = &frame->mbs[x + y * pEnc->mbParam.mb_width];                          MACROBLOCK * const mb = &frame->mbs[x + y * pEnc->mbParam.mb_width];
2081    
# Line 2110  Line 2119 
2119                          stop_coding_timer();                          stop_coding_timer();
2120                  }                  }
2121          }          }
   
         if (pEnc->num_threads > 0) {  
                 void * status;  
                 int k;  
                 for (k = 0; k < pEnc->num_threads; k++) {  
                         pthread_join(pEnc->motionData[k].handle, &status);  
                 }  
         }  
   
2122          emms();          emms();
2123    
2124          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.1770

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