[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.135.2.6, Thu Apr 7 19:07:36 2011 UTC revision 1.139, Thu Feb 3 15:11:57 2011 UTC
# Line 449  Line 449 
449    
450          /* multithreaded stuff */          /* multithreaded stuff */
451          if (create->num_threads > 0) {          if (create->num_threads > 0) {
 #ifndef HAVE_PTHREAD  
                 int t = MAX(1, create->num_threads);  
 #else  
452                  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 */
 #endif  
453                  int threads_per_slice = MAX(1, (t / pEnc->num_slices));                  int threads_per_slice = MAX(1, (t / pEnc->num_slices));
454                  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;
455    
# Line 1651  Line 1647 
1647          int num_threads = MAX(1, MIN(pEnc->num_threads, num_slices));          int num_threads = MAX(1, MIN(pEnc->num_threads, num_slices));
1648          int slices_per_thread = (num_slices*1024 / num_threads);          int slices_per_thread = (num_slices*1024 / num_threads);
1649          int mb_height = pEnc->mbParam.mb_height;          int mb_height = pEnc->mbParam.mb_height;
 #ifdef HAVE_PTHREAD  
1650          void * status = NULL;          void * status = NULL;
 #endif  
1651          uint16_t k;          uint16_t k;
1652    
1653          pEnc->mbParam.m_rounding_type = 1;          pEnc->mbParam.m_rounding_type = 1;
# Line 1694  Line 1688 
1688          pEnc->smpData[0].bs = bs;          pEnc->smpData[0].bs = bs;
1689          pEnc->smpData[0].sStat = &pEnc->current->sStat;          pEnc->smpData[0].sStat = &pEnc->current->sStat;
1690    
 #ifdef HAVE_PTHREAD  
1691          /* create threads */          /* create threads */
1692          for (k = 1; k < num_threads; k++) {          for (k = 1; k < num_threads; k++) {
1693                  pthread_create(&pEnc->smpData[k].handle, NULL,                  pthread_create(&pEnc->smpData[k].handle, NULL,
1694                                 (void*)SliceCodeI, (void*)&pEnc->smpData[k]);                                 (void*)SliceCodeI, (void*)&pEnc->smpData[k]);
1695          }          }
 #endif  
1696    
1697          SliceCodeI(&pEnc->smpData[0]);          SliceCodeI(&pEnc->smpData[0]);
1698    
 #ifdef HAVE_PTHREAD  
1699          /* wait until all threads are finished */          /* wait until all threads are finished */
1700          for (k = 1; k < num_threads; k++) {          for (k = 1; k < num_threads; k++) {
1701                  pthread_join(pEnc->smpData[k].handle, &status);                  pthread_join(pEnc->smpData[k].handle, &status);
1702          }          }
 #endif  
1703    
1704          pEnc->current->length = BitstreamLength(bs) - (bits/8);          pEnc->current->length = BitstreamLength(bs) - (bits/8);
1705    
# Line 1918  Line 1908 
1908    
1909          int k = 0, bound = 0, num_slices = pEnc->num_slices;          int k = 0, bound = 0, num_slices = pEnc->num_slices;
1910          int num_threads = MAX(1, MIN(pEnc->num_threads, num_slices));          int num_threads = MAX(1, MIN(pEnc->num_threads, num_slices));
 #ifdef HAVE_PTHREAD  
1911          void * status = NULL;          void * status = NULL;
         int threads_per_slice = (pEnc->num_threads*1024 / num_threads);  
 #endif  
1912          int slices_per_thread = (num_slices*1024 / num_threads);          int slices_per_thread = (num_slices*1024 / num_threads);
1913            int threads_per_slice = (pEnc->num_threads*1024 / num_threads);
1914    
1915          IMAGE *pRef = &reference->image;          IMAGE *pRef = &reference->image;
1916    
1917          if (!reference->is_edged) {          if (!reference->is_edged) {
1918                  start_timer();                  start_timer();
1919                  image_setedges(pRef, pParam->edged_width, pParam->edged_height,                  image_setedges(pRef, pParam->edged_width, pParam->edged_height,
1920                                             pParam->width, pParam->height, XVID_BS_VERSION);                                             pParam->width, pParam->height, 0);
1921                  stop_edges_timer();                  stop_edges_timer();
1922                  reference->is_edged = 1;                  reference->is_edged = 1;
1923          }          }
# Line 2017  Line 2005 
2005                  }                  }
2006          }          }
2007    
 #ifdef HAVE_PTHREAD  
2008          if (pEnc->num_threads > 0) {          if (pEnc->num_threads > 0) {
2009    
2010                  /* multithreaded motion estimation - dispatch threads */                  /* multithreaded motion estimation - dispatch threads */
# Line 2072  Line 2059 
2059                                  current->fcode = pEnc->smpData[k].minfcode;                                  current->fcode = pEnc->smpData[k].minfcode;
2060                  }                  }
2061    
2062          } else          } else {
 #endif  
         {  
2063    
2064                  /* regular ME */                  /* regular ME */
2065    
# Line 2118  Line 2103 
2103          pEnc->smpData[0].bs = bs;          pEnc->smpData[0].bs = bs;
2104          pEnc->smpData[0].sStat = &current->sStat;          pEnc->smpData[0].sStat = &current->sStat;
2105    
 #ifdef HAVE_PTHREAD  
2106          /* create threads */          /* create threads */
2107          for (k = 1; k < num_threads; k++) {          for (k = 1; k < num_threads; k++) {
2108                  pthread_create(&pEnc->smpData[k].handle, NULL,                  pthread_create(&pEnc->smpData[k].handle, NULL,
2109                          (void*)SliceCodeP, (void*)&pEnc->smpData[k]);                          (void*)SliceCodeP, (void*)&pEnc->smpData[k]);
2110          }          }
 #endif  
2111    
2112          SliceCodeP(&pEnc->smpData[0]);          SliceCodeP(&pEnc->smpData[0]);
2113    
 #ifdef HAVE_PTHREAD  
2114          /* wait until all threads are finished */          /* wait until all threads are finished */
2115          for (k = 1; k < num_threads; k++) {          for (k = 1; k < num_threads; k++) {
2116                  pthread_join(pEnc->smpData[k].handle, &status);                  pthread_join(pEnc->smpData[k].handle, &status);
2117          }          }
 #endif  
2118    
2119          current->length = BitstreamLength(bs) - (bits/8);          current->length = BitstreamLength(bs) - (bits/8);
2120    
# Line 2296  Line 2277 
2277          int bits = BitstreamPos(bs);          int bits = BitstreamPos(bs);
2278          int k = 0, bound = 0, num_slices = pEnc->num_slices;          int k = 0, bound = 0, num_slices = pEnc->num_slices;
2279          int num_threads = MAX(1, MIN(pEnc->num_threads, num_slices));          int num_threads = MAX(1, MIN(pEnc->num_threads, num_slices));
 #ifdef HAVE_PTHREAD  
2280          void * status = NULL;          void * status = NULL;
         int threads_per_slice = (pEnc->num_threads*1024 / num_threads);  
 #endif  
2281          int slices_per_thread = (num_slices*1024 / num_threads);          int slices_per_thread = (num_slices*1024 / num_threads);
2282            int threads_per_slice = (pEnc->num_threads*1024 / num_threads);
2283    
2284          IMAGE *f_ref = &pEnc->reference->image;          IMAGE *f_ref = &pEnc->reference->image;
2285          IMAGE *b_ref = &pEnc->current->image;          IMAGE *b_ref = &pEnc->current->image;
# Line 2324  Line 2303 
2303          if (!pEnc->reference->is_edged) {          if (!pEnc->reference->is_edged) {
2304                  image_setedges(f_ref, pEnc->mbParam.edged_width,                  image_setedges(f_ref, pEnc->mbParam.edged_width,
2305                                             pEnc->mbParam.edged_height, pEnc->mbParam.width,                                             pEnc->mbParam.edged_height, pEnc->mbParam.width,
2306                                             pEnc->mbParam.height, XVID_BS_VERSION);                                             pEnc->mbParam.height, 0);
2307                  pEnc->reference->is_edged = 1;                  pEnc->reference->is_edged = 1;
2308          }          }
2309    
# Line 2341  Line 2320 
2320          if (!pEnc->current->is_edged) {          if (!pEnc->current->is_edged) {
2321                  image_setedges(b_ref, pEnc->mbParam.edged_width,                  image_setedges(b_ref, pEnc->mbParam.edged_width,
2322                                             pEnc->mbParam.edged_height, pEnc->mbParam.width,                                             pEnc->mbParam.edged_height, pEnc->mbParam.width,
2323                                             pEnc->mbParam.height, XVID_BS_VERSION);                                             pEnc->mbParam.height, 0);
2324                  pEnc->current->is_edged = 1;                  pEnc->current->is_edged = 1;
2325          }          }
2326    
# Line 2367  Line 2346 
2346    
2347          start_timer();          start_timer();
2348    
 #ifdef HAVE_PTHREAD  
2349          if (pEnc->num_threads > 0) {          if (pEnc->num_threads > 0) {
2350    
2351                  /* multithreaded motion estimation - dispatch threads */                  /* multithreaded motion estimation - dispatch threads */
# Line 2423  Line 2401 
2401                          if (pEnc->smpData[k].minbcode > frame->bcode)                          if (pEnc->smpData[k].minbcode > frame->bcode)
2402                                  frame->bcode = pEnc->smpData[k].minbcode;                                  frame->bcode = pEnc->smpData[k].minbcode;
2403                  }                  }
2404          } else          } else {
 #endif  
         {  
2405    
2406                  MotionEstimationBVOP(&pEnc->mbParam, frame,                  MotionEstimationBVOP(&pEnc->mbParam, frame,
2407                                                           ((int32_t)(pEnc->current->stamp - frame->stamp)),                              /* time_bp */                                                           ((int32_t)(pEnc->current->stamp - frame->stamp)),                              /* time_bp */
# Line 2475  Line 2451 
2451                  }                  }
2452          }          }
2453    
 #ifdef HAVE_PTHREAD  
2454          for (k = 1; k < num_threads; k++) {          for (k = 1; k < num_threads; k++) {
2455                  pthread_create(&pEnc->smpData[k].handle, NULL,                  pthread_create(&pEnc->smpData[k].handle, NULL,
2456                          (void*)SliceCodeB, (void*)&pEnc->smpData[k]);                          (void*)SliceCodeB, (void*)&pEnc->smpData[k]);
2457          }          }
 #endif  
2458    
2459          pEnc->smpData[0].bs = bs;          pEnc->smpData[0].bs = bs;
2460          pEnc->smpData[0].sStat = &frame->sStat;          pEnc->smpData[0].sStat = &frame->sStat;
2461          SliceCodeB(&pEnc->smpData[0]);          SliceCodeB(&pEnc->smpData[0]);
2462    
 #ifdef HAVE_PTHREAD  
2463          for (k = 1; k < num_threads; k++) {          for (k = 1; k < num_threads; k++) {
2464                  pthread_join(pEnc->smpData[k].handle, &status);                  pthread_join(pEnc->smpData[k].handle, &status);
2465          }          }
 #endif  
2466    
2467          frame->length = BitstreamLength(bs) - (bits/8);          frame->length = BitstreamLength(bs) - (bits/8);
2468    

Legend:
Removed from v.1.135.2.6  
changed lines
  Added in v.1.139

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