[cvs] / xvidcore / src / encoder.c Repository:
ViewVC logotype

Diff of /xvidcore/src/encoder.c

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

revision 1.140, Tue Mar 8 19:16:26 2011 UTC revision 1.141, Wed Apr 6 14:30:14 2011 UTC
# Line 449  Line 449 
449    
450          /* multithreaded stuff */          /* multithreaded stuff */
451          if (create->num_threads > 0) {          if (create->num_threads > 0) {
452    #ifndef HAVE_PTHREAD
453                    int t = MAX(1, create->num_threads);
454    #else
455                  int t = MIN(create->num_threads, (int) (pEnc->mbParam.mb_height>>1)); /* at least two rows per thread */                  int t = MIN(create->num_threads, (int) (pEnc->mbParam.mb_height>>1)); /* at least two rows per thread */
456    #endif
457                  int threads_per_slice = MAX(1, (t / pEnc->num_slices));                  int threads_per_slice = MAX(1, (t / pEnc->num_slices));
458                  int rows_per_thread = (pEnc->mbParam.mb_height + threads_per_slice - 1) / threads_per_slice;                  int rows_per_thread = (pEnc->mbParam.mb_height + threads_per_slice - 1) / threads_per_slice;
459    
# Line 1647  Line 1651 
1651          int num_threads = MAX(1, MIN(pEnc->num_threads, num_slices));          int num_threads = MAX(1, MIN(pEnc->num_threads, num_slices));
1652          int slices_per_thread = (num_slices*1024 / num_threads);          int slices_per_thread = (num_slices*1024 / num_threads);
1653          int mb_height = pEnc->mbParam.mb_height;          int mb_height = pEnc->mbParam.mb_height;
1654    #ifdef HAVE_PTHREAD
1655          void * status = NULL;          void * status = NULL;
1656    #endif
1657          uint16_t k;          uint16_t k;
1658    
1659          pEnc->mbParam.m_rounding_type = 1;          pEnc->mbParam.m_rounding_type = 1;
# Line 1688  Line 1694 
1694          pEnc->smpData[0].bs = bs;          pEnc->smpData[0].bs = bs;
1695          pEnc->smpData[0].sStat = &pEnc->current->sStat;          pEnc->smpData[0].sStat = &pEnc->current->sStat;
1696    
1697    #ifdef HAVE_PTHREAD
1698          /* create threads */          /* create threads */
1699          for (k = 1; k < num_threads; k++) {          for (k = 1; k < num_threads; k++) {
1700                  pthread_create(&pEnc->smpData[k].handle, NULL,                  pthread_create(&pEnc->smpData[k].handle, NULL,
1701                                 (void*)SliceCodeI, (void*)&pEnc->smpData[k]);                                 (void*)SliceCodeI, (void*)&pEnc->smpData[k]);
1702          }          }
1703    #endif
1704    
1705          SliceCodeI(&pEnc->smpData[0]);          SliceCodeI(&pEnc->smpData[0]);
1706    
1707    #ifdef HAVE_PTHREAD
1708          /* wait until all threads are finished */          /* wait until all threads are finished */
1709          for (k = 1; k < num_threads; k++) {          for (k = 1; k < num_threads; k++) {
1710                  pthread_join(pEnc->smpData[k].handle, &status);                  pthread_join(pEnc->smpData[k].handle, &status);
1711          }          }
1712    #endif
1713    
1714          pEnc->current->length = BitstreamLength(bs) - (bits/8);          pEnc->current->length = BitstreamLength(bs) - (bits/8);
1715    
# Line 1908  Line 1918 
1918    
1919          int k = 0, bound = 0, num_slices = pEnc->num_slices;          int k = 0, bound = 0, num_slices = pEnc->num_slices;
1920          int num_threads = MAX(1, MIN(pEnc->num_threads, num_slices));          int num_threads = MAX(1, MIN(pEnc->num_threads, num_slices));
1921    #ifdef HAVE_PTHREAD
1922          void * status = NULL;          void * status = NULL;
         int slices_per_thread = (num_slices*1024 / num_threads);  
1923          int threads_per_slice = (pEnc->num_threads*1024 / num_threads);          int threads_per_slice = (pEnc->num_threads*1024 / num_threads);
1924    #endif
1925            int slices_per_thread = (num_slices*1024 / num_threads);
1926    
1927          IMAGE *pRef = &reference->image;          IMAGE *pRef = &reference->image;
1928    
# Line 2005  Line 2017 
2017                  }                  }
2018          }          }
2019    
2020    #ifdef HAVE_PTHREAD
2021          if (pEnc->num_threads > 0) {          if (pEnc->num_threads > 0) {
2022    
2023                  /* multithreaded motion estimation - dispatch threads */                  /* multithreaded motion estimation - dispatch threads */
# Line 2059  Line 2072 
2072                                  current->fcode = pEnc->smpData[k].minfcode;                                  current->fcode = pEnc->smpData[k].minfcode;
2073                  }                  }
2074    
2075          } else {          } else
2076    #endif
2077            {
2078    
2079                  /* regular ME */                  /* regular ME */
2080    
# Line 2103  Line 2118 
2118          pEnc->smpData[0].bs = bs;          pEnc->smpData[0].bs = bs;
2119          pEnc->smpData[0].sStat = &current->sStat;          pEnc->smpData[0].sStat = &current->sStat;
2120    
2121    #ifdef HAVE_PTHREAD
2122          /* create threads */          /* create threads */
2123          for (k = 1; k < num_threads; k++) {          for (k = 1; k < num_threads; k++) {
2124                  pthread_create(&pEnc->smpData[k].handle, NULL,                  pthread_create(&pEnc->smpData[k].handle, NULL,
2125                          (void*)SliceCodeP, (void*)&pEnc->smpData[k]);                          (void*)SliceCodeP, (void*)&pEnc->smpData[k]);
2126          }          }
2127    #endif
2128    
2129          SliceCodeP(&pEnc->smpData[0]);          SliceCodeP(&pEnc->smpData[0]);
2130    
2131    #ifdef HAVE_PTHREAD
2132          /* wait until all threads are finished */          /* wait until all threads are finished */
2133          for (k = 1; k < num_threads; k++) {          for (k = 1; k < num_threads; k++) {
2134                  pthread_join(pEnc->smpData[k].handle, &status);                  pthread_join(pEnc->smpData[k].handle, &status);
2135          }          }
2136    #endif
2137    
2138          current->length = BitstreamLength(bs) - (bits/8);          current->length = BitstreamLength(bs) - (bits/8);
2139    
# Line 2277  Line 2296 
2296          int bits = BitstreamPos(bs);          int bits = BitstreamPos(bs);
2297          int k = 0, bound = 0, num_slices = pEnc->num_slices;          int k = 0, bound = 0, num_slices = pEnc->num_slices;
2298          int num_threads = MAX(1, MIN(pEnc->num_threads, num_slices));          int num_threads = MAX(1, MIN(pEnc->num_threads, num_slices));
2299    #ifdef HAVE_PTHREAD
2300          void * status = NULL;          void * status = NULL;
         int slices_per_thread = (num_slices*1024 / num_threads);  
2301          int threads_per_slice = (pEnc->num_threads*1024 / num_threads);          int threads_per_slice = (pEnc->num_threads*1024 / num_threads);
2302    #endif
2303            int slices_per_thread = (num_slices*1024 / num_threads);
2304    
2305          IMAGE *f_ref = &pEnc->reference->image;          IMAGE *f_ref = &pEnc->reference->image;
2306          IMAGE *b_ref = &pEnc->current->image;          IMAGE *b_ref = &pEnc->current->image;
# Line 2346  Line 2367 
2367    
2368          start_timer();          start_timer();
2369    
2370    #ifdef HAVE_PTHREAD
2371          if (pEnc->num_threads > 0) {          if (pEnc->num_threads > 0) {
2372    
2373                  /* multithreaded motion estimation - dispatch threads */                  /* multithreaded motion estimation - dispatch threads */
# Line 2401  Line 2423 
2423                          if (pEnc->smpData[k].minbcode > frame->bcode)                          if (pEnc->smpData[k].minbcode > frame->bcode)
2424                                  frame->bcode = pEnc->smpData[k].minbcode;                                  frame->bcode = pEnc->smpData[k].minbcode;
2425                  }                  }
2426          } else {          } else
2427    #endif
2428            {
2429    
2430                  MotionEstimationBVOP(&pEnc->mbParam, frame,                  MotionEstimationBVOP(&pEnc->mbParam, frame,
2431                                                           ((int32_t)(pEnc->current->stamp - frame->stamp)),                              /* time_bp */                                                           ((int32_t)(pEnc->current->stamp - frame->stamp)),                              /* time_bp */
# Line 2451  Line 2475 
2475                  }                  }
2476          }          }
2477    
2478    #ifdef HAVE_PTHREAD
2479          for (k = 1; k < num_threads; k++) {          for (k = 1; k < num_threads; k++) {
2480                  pthread_create(&pEnc->smpData[k].handle, NULL,                  pthread_create(&pEnc->smpData[k].handle, NULL,
2481                          (void*)SliceCodeB, (void*)&pEnc->smpData[k]);                          (void*)SliceCodeB, (void*)&pEnc->smpData[k]);
2482          }          }
2483    #endif
2484    
2485          pEnc->smpData[0].bs = bs;          pEnc->smpData[0].bs = bs;
2486          pEnc->smpData[0].sStat = &frame->sStat;          pEnc->smpData[0].sStat = &frame->sStat;
2487          SliceCodeB(&pEnc->smpData[0]);          SliceCodeB(&pEnc->smpData[0]);
2488    
2489    #ifdef HAVE_PTHREAD
2490          for (k = 1; k < num_threads; k++) {          for (k = 1; k < num_threads; k++) {
2491                  pthread_join(pEnc->smpData[k].handle, &status);                  pthread_join(pEnc->smpData[k].handle, &status);
2492          }          }
2493    #endif
2494    
2495          frame->length = BitstreamLength(bs) - (bits/8);          frame->length = BitstreamLength(bs) - (bits/8);
2496    

Legend:
Removed from v.1.140  
changed lines
  Added in v.1.141

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